Perl Operators

Perl Operators

In Perl, the comparison operators are divided into two classes:

  • Comparison operators that work with numbers
  • Comparison operators that work with strings

Integer-Comparison Operators

Operator Description  

        Greater than

==       Equal to

=       Greater than or equal to

!=       Not equal to

 Comparison returning 1, 0, or -1

Each of these operators yields one of two values:

  • True, or nonzero
  • False, or zero

The operator is a special case. Unlike the other integer comparison operators, returns one of three values:

  • 0, if the two values being compared are equal
  • 1, if the first value is greater
  • -1, if the second value is greater

String-Comparison Operators

For every numeric-comparison operator, Perl defines an equivalent string-comparison operator.

String operator Comparison operation 

lt              Less than

gt              Greater than

eq              Equal to

le              Less than or equal to

ge              Greater than or equal to

ne              Not equal to !=

cmp             Compare, returning 1, 0, or -1

Example

#!/usr/bin/perl
 
$a="coding-school.com";

$b="www.coding-school.com";

if($a eq $b)

{

print "Both are same";

}

else

{

print "Both are different";

}

If you have found my website useful, please consider buying me a coffee below 😉