# Perl operator

The

administrator 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

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

#!/usr/bin/perl\$a= 10 ; \$b = 20 ; print "\$a = \$a , \$b = \$bn" ; \$c = \$a + \$b; print '\$a + \$b = ' . \$c . "n"; \$c = \$a - \$b; print '\$a - \$b = ' . \$c . "n"; \$c = \$a * \$b; print '\$a * \$b = ' . \$c . "n"; \$c = \$a / \$b; Print '\$a / \$b = ' . \$c . "n "; \$c = \$a % \$b; Print '\$a % \$b = ' . \$c. "n"; \$a = 2; \$b = 4; \$c = \$a ** \$b; Print '\$a ** \$b = ' . \$c . "n";

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

#!/usr/bin/perl \$a= 10 ; \$b = 20 ; print "\$a = \$a , \$b = \$bn" ; if( \$a == \$b ) print "\$a == \$b results actualn"; else print "\$a == \$b end result faken"; if( \$a != \$b ) print "\$a != \$b end result genuinen"; else print "\$a != \$b result faken"; \$c = \$a <=> \$b; print "\$a <=> \$ b Back\$cn"; if( \$a > \$b ) print "\$a > \$b result propern"; else print "\$a > \$b result falsen"; if( \$a >= \$b ) print "\$a >= \$b Result propern"; else print "\$a >= \$b Result falsen"; if( \$a < \$b ) print "\$a < \$b result authenticn"; else print "\$a < \$b result faken"; if( \$a <= \$b ) print "\$a <= \$b Result authenticn"; else print "\$a <= \$b Result falsen";

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

#!/usr/bin/perl if( \$a gt \$b ) print "\$a gt \$b returns actualn"; else print "\$a gt \$b returns falsen"; if( \$a le \$b ) print "\$a le \$b returns truen"; else print "\$a le \$b returns faken"; if( \$a ge \$b ) print "\$a ge \$b returns propern"; else print "\$a ge \$b returns faken"; if( \$a ne \$b ) print "\$a ne \$b returns authenticn"; else print "\$a ne \$b returns faken"; \$c = \$a cmp \$b; print "\$a cmp \$b returns\$cn";

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

#!/usr/bin/perl \$a= 10 ; \$b = 20 ; print "\$a = \$a ,\$b = \$bn" ; \$c = \$a + \$b; print "After venture\$c = \$cn"; \$c += \$a; print "\$c = \$c , mathematics announcement\$c += \$an"; \$c -= \$a; print "\$c = \$c , arithmetic declaration\$c -= \$an"; \$c *= \$a; print "\$c = \$c , mathematics announcement\$c *= \$an"; \$c /= \$a; Print "\$c = \$c , operation declaration \$c /= \$an"; \$c %= \$a; Print "\$c = \$c ,Operation Statement \$c %= \$an"; \$c = 2; \$a = four; Print "\$a = \$a , \$c = \$cn" ; \$c **= \$a; Print "\$c = \$c ,Operation Statement \$c **= \$a n";

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

The

bitwise 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

#!/usr/bin/perl use integer; \$a = 60 ; \$b = thirteen \$b = \$cn"; \$c = \$a ^ \$b; print "\$a ^ \$b = \$cn"; \$c = ~\$a; print "~\$a = \$cn"; \$c = \$a << 2; print "\$a << 2 = \$cn"; \$c = \$a >> 2; print "\$a >> 2 = \$cn";

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 the

table 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

#!/usr/bin/perl \$a = actual ; \$b = fake0 ; \$c= no longer (\$a); print "no longer(\$a)= \$cn";

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

The

Perl quote operator is proven inside the following desk.

Operator Description Instance
q Add unmarried prices to the string qabcd The end result is 'abcd'
qq Add double fees to the string qqabcd The end result is "abcd"
qx Add backquotes to strings qxabcd The result is `abcd`

## Instance

#!/usr/bin/perl \$a= 10 ; \$b = qa = \$a; print "qa = \$a = \$bn"; \$b = qqa = \$a; print "qqa = \$a = \$bn"; # Execute with Unix's date command \$t= qx date; Print "qxdate = \$tn";

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

#!/usr/bin/perl

\$a = " we";
\$b = " LOOKUPS";

print "\$a = \$a , \$b = \$bn" ;

\$c = \$a . \$b;
print "\$a . \$b = \$cn";

\$c= " -" x 3;
print ""-" x three = \$cn";

@c = ( 2..Five);
print "(2..Five) = @cn";

\$a= 10 ;
\$b= 15 ;
print "\$a = \$a , \$b = \$bn" ;

\$a++;
\$c = \$a ;
print "\$a Execution\$a++ = \$cn";

\$b--;
\$c = \$b ;
print "\$b Execute\$b-- = \$cn";

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>OperatorCombination++, -- None-, ~, !From proper to left **From right to left=~, !~From left to Right *, /, %, xfrom left to right +, -, .Left to proper<<, >>from left to right-e, -r,no <, <=, >, >=, lt, le, gt, geLeft to right< /td>==, !=, <=>, eq, ne, cmpFrom 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 leftother,from left to rightnow notfrom left to rightandLeft to rightor, xorFrom left to proper < Br>

Instance

#!/usr/bin/perl

\$a = 20 ;
\$b = 10 ;
\$c= 15 ;
\$d = 5 ;
\$e;

print "\$a = \$a, \$b = \$b, \$ c = \$c ,\$d = \$dn";

\$e = ( \$a + \$b) * \$c / \$d;
Print "(\$a + \$b) * \$c / \$d = \$en";

\$e = ((\$a + \$b) *  \$c )/ \$d;
Print "(( \$a + \$b) * \$c) / \$d = \$en";

\$e = (\$a + \$b) * (\$c / \$d);
print "(\$a + \$b) * (\$c / \$d ) = \$en";

\$e = \$a + (\$b * \$c ) / \$d;
Print "\$a + (\$b * \$c )/ \$d = \$en";

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

```

welookups is optimized for learning.© welookups. 2018 - 2020 All Right Reserved and you agree to have read and accepted our term and condition.