What are the logical operators in Perl?
Logical operators are applies two operands and return a boolean value always.
It supports three operators in operators
Logic And operator( and
or &&)
Logic OR operator( or
or ||
)
Logic Not operator( not
)
Perl Logical Operators
|Parameter | Symbol |Description
|:——–| ————— |
|Logical AND|
and
or&& |Both operands are true,return true,else false| |Logical OR|
oror
|||Both or One of the operands is true, return true, else false| |Logical NOT|
Not `|Returns reverse of Operand value return true, else false|Perl Logical Operators Examples
This is an example of a logical operator with code.
my $opearnd1 = true;
my $operand2 = false;
## logical and
$operand1 && $operand2; ## false
$operand1 and true; ## true
$operand1 || $operand2); ## true
$operand1 or true; ## true
not ($operand1) # false
not ($operand2) # true
Perl Logical Operators Precedence
precedence applied to a group of conditional operators.
During execution, One of them takes the first execution then the others.
It always executes from left to right when there are multiple conditions.
my $opearnd1 = true;
my $operand2 = false;
my $operand3 = false;
$opearnd1 && $opearnd2 || $opearnd3 ## false
In the above,$opearnd1 && $opearnd2
evaluated and result is applied with or operator of $operand3, result is false