You are reading the article A Quick Glance Of 7 Different Types Of Perl Operators updated in September 2023 on the website Lifecanntwaitvn.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested October 2023 A Quick Glance Of 7 Different Types Of Perl Operators
What Perl is?Start Your Free Software Development Course
Web development, programming languages, Software testing & others
Perl OperatorsJust like any other language, the operators in Perl can be categorized in the following categories:
Arithmetic Operators
Equality Operators
Assignment Operators
Bitwise Operators
Logical Operators
Quote-like Operators
Miscellaneous Operators
So, let’s go through Perl operators one by one:
1. Arithmetic OperatorsAs the name suggests Arithmetic Operators are used to doing arithmetic operations like subtraction addition etc.
+ (Addition): It used to add values on either side of the addition operator: $a + $b =40
– (Subtraction): It is used to subtract right hand side from left hand side: $b – $a =10
* (Multiplication): It is used to multiply values on either side of the operator $a * $b =300
/ (Division): It is used to divide the left-hand operand by the right-hand operand $b / $a = 3
% (Modulus): It is used to divide the left-hand operand by the right-hand operand and return remainder $b % $a = 0
** (Exponential): It is used to perform power calculation $b ** $a gives 30 raised to power 10.
2. Equality OperatorsThese are called relational operator so let’s keep the values of both a and b same as they were in the case of arithmetic operators:
== (equal to): As the name suggests, checks if the value of two operands is equal or not if they are equal it becomes true. In this case $a == $b is not true.
!= (not equal to): As the name suggests, checks if the value of two operands is equal or not if they are not equal it becomes true. In this case $a != $b is true
< (Less than): This operator checks if the value of two operands is less than each other or not $a < $b is true.
<= (Less than equal to): This operator checks that if the value of two operands is less than or equal to each other. In our case $a <= $b is true.
Now let’s check string equality operators in Perl, let’s change value as $a =”nil” and $b = “abc”
It: It checks if the left wise string argument is less than the right wise string argument. In our case, $a It $b is not true.
gt: It checks if the left wise string argument is greater than the right wise string argument. In our case, $a gt $b is true.
le: It checks if the left wise string argument is less than or equal to the right wise string argument. In our case, $a Ie $b is false
ge: It checks if the left wise string argument is greater than or equal to the right wise string argument. In our case, $a ge $b is false.
3. Assignment OperatorsLet’s change the value of a and b to previous values of 10 and 30. Perl supports the following Assignment operators:
=: It is an assignment operator. It assigns the value from the right-hand side to the left-hand side, for example, $c = $a + $ b which makes the value of c to 40.
+=: It is called add AND assignment operator. It adds the right operand to left operand and assigns the value of the result to left operand.
-=: It is called Subtract AND assignment operator. It subtracts the right operand from left operand and assigns the value of the result to left operand.
*=: It is called multiple AND assignment operator. It multiplies the right operand from left operand and assigns the value of the result to the left operand.
/=: It is called Divide AND assignment operator. It divides the right operand from left operand and assigns the value of the result to left operand.
4. Bitwise Operators
& (Binary and): It copies bits to result which are in both operands.
^ (Binary XOR): It copies a bit if it is set in one operand, not both.
5. Logical OperatorsPerl contains the following logical operators:
And (Logical AND): If both operands become true then the operator returns true.
OR (Logical OR): If any of the operands is non-zero then it becomes true.
Not (Logical NOT): It reverses the logical state of the operand.
6. Quota Like OperatorsPerl supports the following Quota Like operators:
q{}: It encloses a string in single quotes. for example q{nil} becomes ‘nil’.
qq{}: It encloses a string in double-quotes. for example qq{nil} becomes “nil”.
qx{}: It encloses a string in reverse quotes.
7. Miscellaneous OperatorsPerl contains the following Miscellaneous operators:
. (Binary Operator dot): It is used to concatenate two strings. If $a =”nil” and $b = “def” $a.$b =”nildef”.
x (Repetition Operator): It returns a string of repeated left side operand. The number of repetitions is specified by the right-hand side operand. For example: (‘-‘ x 3) gives ‘—‘.
++ (Auto increment Operator): It will increase the value by one. The value must be an integer. For example: if $a =10 $a++ gives 11.
— (Auto decrement Operator): It will decrease the value by one. The value must be an integer. For example: if $a =10 $a– will give 9.
Recommended ArticlesThis has been a guide to Perl Operators. Here we have discuss 7 different types of Perl Operators along with respective examples. You can also go through our other suggested articles to learn more –
You're reading A Quick Glance Of 7 Different Types Of Perl Operators
Update the detailed information about A Quick Glance Of 7 Different Types Of Perl Operators on the Lifecanntwaitvn.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!