Perl Logical Operators

There are following logical operators supported by Perl language. Assume variable $a holds true and variable $b holds false then −

Sr.No.Operator & Description
Called Logical AND operator. If both the operands are true then the condition becomes true.

Example− ($a and $b) is false.

C-style Logical AND Operator copies a bit to the result if it exists in both operands
Example− ($a && $b) is false.
Called Logical OR Operator. If any of the two operands are non zero then condition becomes true.
Example− ($a or $b) is true.
C-style Logical OR Operator copies a bit if it exists in either operand.p>
Example− ($a || $b) is true.
Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false.
Example− not($a and $b) is true.

Quote-like Operators

There are following quote-like operators supported by Perl language. In the following table, a {} represents any pair of delimiters you choose.

Sr.No.Operator & Description
1q{ }
Encloses a string with-in single quotes

Example− q{abcd} gives 'abcd'

2qq{ }
Encloses a string with-in double quotes
Example− qq{abcd} gives "abcd"
       3qx{ }
Encloses a string with-in invert quotes
Example− qx{abcd} gives `abcd`

Updated on: 29-Nov-2019


Kickstart Your Career

Get certified by completing the course

Get Started