# Perl operator

Theadministrator is an image that advises the compiler to perform explicit scientific or intelligent tasks, together with: 3+2=five.

The Perl language has many coordinated administrators. We should view some typical ones:

- Arithmetic Operators
- Comparative operators
- Logical Operators
- Assignment Operator
- Bit Operator
- Quotation operators
- Other Operators
- Operator Priorities

## Arithmetic Operators

In the work area precedent we set the variable $a to ten and $b to 20.

Operator | Description | Instance |
---|---|---|

+ | addition | $a + $b The outcome is 30 |

- | Subtraction | $a - $b The outcome is - 10 |

* | multiplication operation | $a * $b The outcome is two hundred |

/ | Division Operation | $b/$a The outcome is 2 |

% | Residual task, leftover portion after divisibility | $b % $a The final product is zero |

** | Power | $a**$b The outcome is 10 to the 20 th energy |

## Instance

The above program execution output is:

$a = 10 , $b = 20 $a + $b = 30 $a - $b = -10 $a * $b = 2 hundred $a / $b = zero.Five $a % $b = 10 $a ** $b = 16

## Comparative operator

In the work area occurrence we set the variable $a to 10 and $b to 20.

Operator | Description | Instance |
---|---|---|

== | Checks whether the qualities of the two operands are indistinguishable. In the event that they're same, the circumstance is valid, in some other case it is false. | ($a == $b) is false |

!= | Checks if the qualities of the two operands are same. On the off chance that they are not same, the condition is real, else it is false. | ($a != $b) is appropriate. |

<=> | Checks whether the qualities of the 2 operands are indistinguishable. In the event that the amount at the left is not exactly the number on the right, - 1 is back. In the event that the assortment on the left is zero, the wide assortment at the left is additional than 1 at the best possible. | ($a <=> $b) returns - 1. |

> | Checks if the estimation of the left operand is more than the expense of the best possible operand, if real the circumstance is true, generally false. | ($a > $b) returns counterfeit. |

< | Checks if the expense of the left operand is not exactly the cost of the correct operand, and provided that this is true, the situation is valid, in some other case it returns counterfeit. | ($a < $b) returns genuine. |

>= | Checks if the estimation of the left operand is additional than or indistinguishable to the cost of the correct operand, and assuming this is the case, the situation is valid, else it returns counterfeit. | ($a >= $b) returns false. |

<= | Checks if the estimation of the left operand is not exactly or indistinguishable to the expense of the correct operand, and all things considered, the condition is real, in some other case it returns counterfeit. . | ($a <= $b) returns valid. |

## Instance

The above software execution output is:

$a = 10 , $b = 20 $a == $b Results false $a != $b Results actual $a <=> $b go back -1 $a > $b Results fake $a >= $b Results fake $a < $b Results genuine $a <= $b Results real

In the desk underneath, the variable $a is ready to "abc" and $b is "xyz" , and the assessment operator is used to calculate the end result.

Operator | Description | Instance |
---|---|---|

lt | Check if the string on the left is smaller than the string at the proper, if it returns actual, otherwise it returns false. | ($a lt $b) returns actual. |

gt | Check if the string at the left is greater than the string at the right, if it returns real, otherwise it returns false. | ($a gt $b) returns fake. |

le | Checks if the string on the left is much less than or same to the string on the proper, if it returns genuine, otherwise it returns false. | ($a le $b) returns true |

ge | Check if the string at the left is more than or same to the string at the proper, if proper, in any other case return fake. | ($a ge $b) returns false. |

eq | Checks if the string at the left is identical to the string on the right, if it returns true, otherwise it returns fake. | ($a eq $b) returns false. |

ne | Check if the string at the left isn't identical to the string on the right, if it returns actual, in any other case it returns false. | ($a ne $b) returns proper |

cmp | If the string at the left is greater than the string on the proper, it returns 1. If it returns same to zero, if the string on the left is smaller than the string at the proper, it returns -1. | ($a cmp $b) returns -1. |

## Instance

The above application execution output is:

$a = abc ,$b = xyz Abc lt $b return genuine $a gt $b go back fake $a le $b go back true $a ge $b go back false $a ne $b go back authentic $a cmp $b return -1

## Assignment Operator

In the table example we set the variable $a to ten and $b to twenty.

Operator | Description | Instance |
---|---|---|

= | Simple assignment operator assigns the cost of the right operand to the left operand | $c = $a + $b will assign the price of $a + $b to $c |

+= | Add and assign operator, assign the end result of the proper operand plus the left operand to the left operand | $c += $a is identical to $c = $c + $a |

-= | minus the task operator, assigning the end result of the left operand minus the right operand to the left operand | $c -= $a is identical to $c = $c - $a |

*= | Multiply and assign operator, assign the end result of multiplying the proper operand to the left operand to the left operand | $c *= $a is identical to $c = $c * $a |

/= | In addition to the mission operator, the result of dividing the left operand via the right operand is assigned to the left operand | $c /= $a is identical to $c = $c / $a |

%= | Find the modulo and assign operator, and discover the modulo assignment of the 2 operands to the left operand | $c %= $a is identical to $c = $c % a |

**= | energy and task operator, compare the electricity of operands to the left operand | $c **= $a is same to $c = $c ** $a |

## Instance

The above software execution output is:

$a = 10 ,$b = 20 After task $c = 30 $c = forty ,Operation Statement $c += $a $c = 30 ,Operation Statement $c -= $a $c = 300 ,Operation Statement $c *= $a $c = 30 ,Operation Statement $c /= $a $c = zero ,Operation Statement $c %= $a $a = 4 , $c = 2 $c = sixteen ,Operation Statement $c **= $a

## bit operations

Thebitwise operator acts on bits and performs operations bit by bit.

Setting $a = 60, $b = 13, now in binary layout, they are$b = 0011 1101 $a^$b = 0011 0001 ~$a = 1100 0011

The bitwise operators supported by using Perl are shown in the following table:

Operator | Description | Instance |
---|---|---|

& | If it exists in each operands, the binary AND operator copies one bit into the result. | ($a & $b) gets 12 and the binary will be 0000 1100 |

present in any operand, the binary OR operator copies one bit into the result. | ($a will get sixty one and the binary may be 0011 1101 | |

^ | If it exists in one of the operands but does no longer exist in both operands, the binary XOR operator copies one bit into the result. | ($a ^ $b) gets forty nine and the binary can be 0011 0001 |

~ | The binary inverse operator is a unary operator with a "turn" bit effect, ie 0 turns into 1, and 1 turns into 0. | (~$a ) gets -61 , the binary is 1100 0011 , the inverse of a signed binary range. |

<< | Binary left shift operator. The fee of the left operand actions to the left by using the quantity of digits distinctive via the proper operand. | $a << 2 will get 240 and the binary may be 1111 0000 |

>> | Binary right shift operator. The price of the left operand moves to the proper by the variety of digits certain by means of the proper operand. | $a >> 2 will get 15 and the binary may be 0000 1111 |

## Instance

The above program execution output is:

$a = 60 , $b = thirteen $b = 61 $a ^ $b = forty nine ~$a = -61 $a << 2 = 240 $a >> 2 = 15

## logical operators

Perl logical operators are proven inside the following desk.

In thetable example we set the variable $a to proper and $b to false.

Operator | Description | Instance |
---|---|---|

and | Logical and operator symbols. The circumstance is real if both operands are proper. | ($a and $b) is false. |

&& | C-style common sense and operator symbols. If each operands are actual, the situation is real | ($a && $b) is fake. |

or | Logic or operator. The condition is authentic if either of the two operands is non-0. | ($a or $b) is authentic. |

style logic or operator. The circumstance is authentic if both of the 2 operands is non-0authentic. | ||

not | Logical non-operator. The logical nation used to reverse the operands. If the situation is genuine, the logical non-operator will make it false. | now not($a and $b) is real. |

## Instance

The above application execution output is:

$a = proper , $b = false $a and $b = false $a && $b = false $a or $b = properproper no longer($a)= 1

## Quotation operation

ThePerl quote operator is proven inside the following desk.

Operator | Description | Instance |
---|---|---|

q | Add unmarried prices to the string | qabcd The end result is 'abcd' |

Add double fees to the string | qqabcd The end result is "abcd" | |

qx | Add backquotes to strings | qxabcd The result is `abcd` |

## Instance

The above software execution output is:

qa = $a = a = $a Qqa = $a = a = 10 Qxdate = 2016Year 6month10day Friday 16time22分332nd CST< /pre>

## Other Operators

In addition to the operators we referred to above, Perl also supports the subsequent operators:

The The

Operator | Description | Instance |
---|---|---|

. | The dot (.) is used to attach strings. | If $a="we", $b="LOOKUPS" , $a.$b effects in "WELOOKUPS" |

x | x operator returns the wide variety of times the string is repeated. | ('-' x 3) The output is ---. |

.. | .. Is the variety operator. | (2..5) The output is (2, three, 4, 5) |

++ | Auto increment operator, integer fee multiplied by means of 1 | $a =10, $a++ will output as eleven |

-- | Decremental operator, integer value reduction 1 | $a =10, $a-- output is nine |

-> | arrow is used to specify a technique for a class | $obj->$a represents the $a way of the item $obj. |

## Instance

The above program execution output is:

$a = we , $b = LOOKUPS $a . $b = WELOOKUPS "-" x 3 = --- (2..5) = 2 three 4 5 $a = 10 , $b = 15 $a Execute $a++ = eleven $b Execute $b-- = 14

## Operator Priority

The following desk lists the operator priority for the Perl language:

< Tr>< Tr>Operator | Combination | |
---|---|---|

++, -- | None | |

-, ~, ! | From proper to left | |

** | From right to left | |

=~, !~ | From left to Right | |

*, /, %, x | from left to right | |

+, -, . | Left to proper | |

<<, >> | from left to right | |

-e, -r, | no | |

<, <=, >, >=, lt, le, gt, ge | Left to right< /td> | |

==, !=, <=>, eq, ne, cmp | From left to Right | |

& | from left to right, ^ | From left to right |

&& | from left to properproper | |

.. | from left to proper | |

? and : | From proper to left | |

=, +=,&n Bsp;-=, *=, | from right to left | |

other | ||

, | from left to right | |

now not | from left to right | |

and | Left to right | |

or, xor | From left to proper < Br> |

## Instance

The above program execution output is:

$a = 20, $b = 10, $c = 15 ,$d = 5 ($a + $b) * $c / $d = 90 (($a + $b) * $c) / $d = 90 ($a + $b) * ($c / $d ) = ninety $a + ($b * $c )/ $d = 50