One, arithmetic operators: + (plus),-(minus), * (multiply),/(except), * * (UP),% (remainder),-(Monocular negative)
(1) The base of the exponentiation can not be negative, such as ( -5) * * 2.5 # error;
(2) The result of a exponentiation cannot exceed the limit indicated by the computer, such as the 999999 # error
(3) The operand of the remainder, if not an integer, is rounded to an integer and the operator to the right cannot be zero
(4) Monocular negative can be used for variables:-$y; # equivalent to $y *-1
(5) corresponding to + =,-=, *=,/=, **=,%=
Second, integer comparison operators
Table 1. Integer comparison Operators
Operator |
Describe |
< |
Less than |
> |
Greater than |
== |
Equals |
<= |
Less than or equal |
>= |
Greater than or equal |
!= |
Not equal to |
<=> |
Compare, return 1, 0,-1 |
The operators <=> results are:
0-Two values equal
1-Large first value
1-Large second value
Three, string comparison operators
Table 2. string comparison operators
Operator |
Describe |
|
Lt |
Less than |
|
Gt |
Greater than |
|
eq |
Equals |
|
Le |
Less than or equal |
|
Ge |
Greater than or equal |
|
Ne |
Not equal to |
|
Cmp |
Compare, return 1, 0, or-1 |
|
Four, logical operators
Logic or: $a | | $b or $a or $b
Logic with: $a && $b or $a and $b
Logical non-:! $a or not $a
Logical XOR: $a XOR $b
Five, bitwise operators
Bits and:&
Bit or: |
Bit non: ~
Bit XOR: ^
Shift Left: $x << 1
Shift Right: $x >> 2
Note: Do not use & for negative integers, because Perl will convert them to unsigned numbers.
Six, assignment operators
Table 3. Assignment operators
Operator |
Describe |
= |
Assignment only |
+= |
Addition and assignment |
-= |
Subtraction and assignment |
*= |
Multiplication and assignment |
/= |
Division and Assignment |
%= |
Remainder and assignment |
**= |
Exponentiation and Assignment |
&= |
Bitwise and and assignment |
|= |
Bitwise OR and Assignment |
^= |
Bitwise XOR and Assignment |
Table 4. Assignment operator Examples
An expression |
An equivalent expression |
$a = 1; |
None (Basic Assignment) |
$a-= 1; |
$a = $a-1; |
$a *= 2; |
$a = $a * 2; |
$a/= 2; |
$a = $a/2; |
$a%= 2; |
$a = $a% 2; |
$a **= 2; |
$a = $a * * 2; |
$a &= 2; |
$a = $a & 2; |
$a |= 2; |
$a = $a | 2; |
$a ^= 2; |
$a = $a ^ 2; |
Note:
1. = can occur multiple times in an assignment statement, such as:
$value 1 = $value 2 = "a string";
2. = as a sub-expression
($a = $b) + = 3;
Equivalent to
$a = $b;