Perl Equality Operators:
These are also called relational operators. Assume variable $a holds 10 and variable $b holds 20 then, let’s check following numeric equality operators:
Operator
|
Description
|
Example
|
==
|
Checks if the values of two operands are equal or not, if
yes then condition becomes true.
|
($a == $b) is not true.
|
!=
|
Checks if the values of two operands are equal or not, if
values are not equal then condition becomes true.
|
($a! = $b) is true.
|
<=>
|
Checks if the value of two operands are equal or not, and
returns -1, 0, or 1 depending on whether the left argument is numerically
less than, equal to, or greater than the right argument.
|
($a <=> $b) returns -1.
|
>
|
Checks if the value of left operand is greater than the
value of right operand, if yes then condition becomes true.
|
($a > $b) is not true.
|
<
|
Checks if the value of left operand is less than the value
of right operand, if yes then condition becomes true.
|
($a < $b) is true.
|
>=
|
Checks if the value of left operand is greater than or
equal to the value of right operand, if yes then condition becomes true.
|
($a >= $b) is not true.
|
<=
|
Checks if the value of left operand is less than or equal
to the value of right operand, if yes then condition becomes true.
|
($a <= $b) is true.
|
Operator
|
Description
|
Example
|
lt
|
Returns true if the left argument is string wise less than
the right argument.
|
($a lt $b) is true.
|
gt
|
Returns true if the left argument is string wise greater
than the right argument.
|
($a gt $b) is false.
|
le
|
Returns true if the left argument is string wise less than
or equal to the right argument.
|
($a le $b) is true.
|
ge
|
Returns true if the left argument is string wise greater
than or equal to the right argument.
|
($a ge $b) is false.
|
eq
|
Returns true if the left argument is string wise equal to the
right argument.
|
($a eq $b) is false.
|
ne
|
Returns true if the left argument is string wise not equal
to the right argument.
|
($a ne $b) is true.
|
cmp
|
Returns -1, 0, or 1 depending on whether the left argument
is string wise less than, equal to, or greater than the right argument.
|
($a cmp $b) is -1.
|
No comments:
Post a Comment