Perl - 运算符介绍

Perl算术运算符

Sr.No.Operator & Description
1

+ (加法)

\$a + \$b=30

2

- (减法)

\$a-\$b=-10

3

* (乘法)

\$a * \$b=200

4

/( 除)

\$b/\$a=2

5

％(取模)

\$b％\$a=0  (整除后的余数)

6

**(指数)

\$a** \$b  10的20次方

Perl关系运算符

Sr.No.Operator & Description
1

==(等于)

(\$a == \$b) is not true。

2

!=(不等于)

(\$a!= \$b) is true。

3

<=>

(\$a <=> \$b) returns -1.

4

> (greater than)

(\$a > \$b) is not true.

5

< (less than)

(\$a < \$b) is true.

6

>= (greater than or equal to)

(\$a >= \$b) is not true.

7

<= (less than or equal to)

(\$a <= \$b) is true.

Sr.No.Operator & Description
1

lt

(\$a lt \$b) is true

2

gt

(\$a gt \$b) is false。

3

le

(\$a le \$b) is true

4

ge

-(\$a ge \$b) is false

5

eq

-(\$a eq \$b) is false

6

ne

(\$a ne \$b) is true

7

cmp

-(\$a cmp \$b) is -1。

Perl赋值运算符

Sr.No.Operator & Description
1

=

\$c= \$a + \$b 将\$a + \$b的值分配给\$c

2

+=

\$c +=\$a等效于\$c= \$c + \$a

3

-=

\$c-= \$a等效于\$c=\$c-\$a

4

*=

\$c *=\$a等效于\$c=\$c * \$a

5

/=

\$c/= \$a等同于\$c=\$c/\$a

6

%=

\$c％= \$a等同于\$c=\$c％a

7

** =

\$c **=\$a等效于\$c=\$c ** \$a

Perl按位运算符

\$a=0011 1100

\$b=0000 1101

-----------------

\$a&\$b=0000 1100

\$a | \$b=0011 1101

\$a ^ \$b=0011 0001

〜\$a=1100 0011

Perl语言支持以下Bitwise运算符,假设\$a=60；和\$b=13

Sr.No.Operator & Description
1

&

2

|

3

^

4

5

<<

6

>>

Perl逻辑运算符

Perl语言支持以下逻辑运算符。假设变量\$a=true,变量\$b= false,然后-

Sr.No.Operator & Description
1

and

2

&&

3

or

4

||

5

not

引用运算符

Perl语言支持以下类似Quote的运算符。在下表中,{}代表您选择的任何一对定界符。

Sr.No.Operator & Description
1

q {}

2

qq {}

3

qx {}

其他运算符

Perl语言支持以下杂类运算符。假设变量a=10,变量b=20,则-

Sr.No.Operator & Description
1

.

2

x

3

..

4

++

5

-

6

->

Perl运算符优先级

```left	terms and list operators (leftward)
left	->
nonassoc	++ --
right	**
right	! ~\and unary + and -
left	=~ !~
left	*/% x
left	+ - .
left	<< >>
nonassoc	named unary operators
nonassoc	< > <= >= lt gt le ge
nonassoc	== != <=> eq ne cmp ~~
left	&
left	| ^
left	&&
left	|| //
nonassoc	..  ...
right	?:
right	= += -= *= etc.
left	, =>
nonassoc	list operators (rightward)
right	not
left	and
left	or xor
```