codescracker


perl

Perl Operators



« Previous Tutorial Next Tutorial »


Operators in perl is basically used to perform mathematical and logical manipulations in perl program. There are following types of operators available in perl:

Perl Arithmetic Operators

Perl arithmetic operators allows you to perform calculation tasks in your perl program. Here the following table lists the arithmetic operators available in perl:

Operator Name Meaning
+ Addition Operator This operator adds the values on either side of the operator
- Subtraction Operator This operator used to subtract the right hand operand from the left hand operand
/ Division Operator This operator used to divide the left hand operand by right hand operand
* Multiplication Operator This operator used to multiply the values on either side of the operator
% Modulus Operator This operator is used to divide the left hand operand by right hand operand and returns remainder
** Exponent Operator This operator basically performs exponential (power) calculation on operators

Perl Equality Operators

Perl equality operators allows you to perform some comparison tasks in your perl program. Here the following table lists the equality operators available in perl:

Operator Meaning
== This operator checks whether the values of the two operands are equal or not equal. If yes, then the condition becomes true, otherwise false
!= This operator checks whether the values of the two operands are equal or not equal. If the values are not equal then the condition becomes true, otherwise the condition becomes false
> This operator checks whether the the value of the left operand is greater than the value of the right operand or not. If yes, then the condition becomes true, otherwise false
< Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true
<=> This operator is used to check whether the value of the two operands are equal or not equal, and returns -1, 0 or 1, depends on whether the left argument is numerically less than, equal to, or greater than the right argument
>= This operator is used to check whether the value of the left operand is greater than or equal to the right or not. If yes, then condition becomes true, otherwise false
<= This operator is used to check whether the value of the left operand is less than or equal to the right or not. If yes, then condition becomes true, otherwise false

Perl Assignment Operators

Perl assignment operators allows you to assign values to a variable in your perl program. Here, the table given below, lists assignment operators available in perl:

Operator Name Meaning
= Simple assignment operator This operator is used to assign values from the right side operands to the left side operand
+= Add AND assignment operator This operator adds the right operand to the left operand and assign the result to the left operand
-= Subtract AND assignment operator This operator subtracts right operand from the left operand and assign the result to the left operand
/= Divide AND assignment operator This operator is used to divide the left operand with the right operand and assign the result to the left operand
*= Multiply AND assignment operator This operator is used to multiply the right operand with the left operand and assign the result to the left operand
**= Exponent AND assignment operator This operator in perl, is used to perform the exponential (power) calculation on operators and assign value to the left operand
%= Modulus AND assignment operator This operator takes modulus using the two operands and assign the result to the left operand

Perl Bitwise Operators

Perl bitwise operators works on bits. The bitwise operators in perl, perform bit by bit operations. Here the following table lists the bitwise operators available in perl:

Operator Name Meaning
& Binary AND Operator This operator is used to copy a bit to the result if it exists in both the operands
| Binary OR Operator This operator is used to copy a bit if it exists in either the operand
^ Binary XOR Operator This operator is used to copy the bit if it is set in one operand but not in both
~ Binary Ones Complement Operator This operator is unary operator and has the effect of 'flipping' bits
>> Binary Right Shift Operator Using this operator in perl, the value of the left operand is moved right by the number of bits specified by the right operand
<< Binary Left Shift Operator Using this operator, the value of the left operand is moved left by the number of bits specified by the right operand

Example

  $a = 0011 1100
& $b = 0000 1101
-----------------
       0000 1100

  $a = 0011 1100
| $b = 0000 1101
-----------------
       0011 1101

  $a = 0011 1100
^ $b = 0000 1101
-----------------
       0011 0001

  $a = 0011 1100
~ $b = 0000 1101
-----------------
       1100 0011

Perl Logical Operators

Perl logical operators allows you to perform some logical manipulations in your perl program. Here the following table lists logical operators available in perl:

Operator Name Meaning
and Logical AND operator This operator is used to check whether both the operands are true or not. If yes, then then condition becomes true, otherwise false
or Logical OR Operator This operator is used to check whether any of the two operands are non zero or not. If yes, then the condition becomes true, otherwise false
&& Logical AND operator This operator is used to copy a bit to the result if it exists in both the operands
|| Logical OR operator This operator is used to copy a bit if it exists in either operand
not Logical NOT Operator This operator used to reverse the logical state of its operand. If a condition is true then the Logical NOT operator makes it false, and if the condition is false, then the logical not operator makes it true

Perl Quote-like Operators

Here, the following table lists the quote-like operators available in perl:

Operator Meaning
q{ } This operator is used to enclose a string with-in single quotes
qx{ } This operator is used to enclose a string with-in invert quotes
qq{ } This operator is used to enclose a string with-in double quotes

Perl Miscellaneous Operators

Here the following table lists the miscellaneous operators available in perl:

Operator Name Meaning
. Binary dot operator This operator in perl, is used to concatenate the two strings
.. Range operator This operator returns a list of values counting from the left value to the right value
x Repetition operator x The repetition operator x in perl, returns a string consisting of the left operand repeated the number of times that is specified by the right operand
++ Auto Increment operator This operator is used to increase the integer value by one
-- Auto Decrement operator This operator is used to decrease the integer value by one
-> Arrow operator This operator is mostly used in dereferencing a method or variable from an/a object/class name

« Previous Tutorial Next Tutorial »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test