"Perl for Perl Newbies" - Part 1ConditionalsNumerical Comparison Operators

7.1. Numerical Comparison Operators

Perl supplies the user with 6 numerical comparison operators which test for the comparison of two numbers. They are:

$x == $y $xand $yare equal.
$x > $y $xis greater than $y
$x < $y $xis lesser than $y
$x >= $y $xis greater or equal to $y
$x <= $y $xis lesser or equal to $y
$x != $y $xis not equal to $y

Those operators can be used inside conditionals and also outside, as part of a normal expression. The following program prints all the numbers between 1 and 100 that are not divisible by 3:

for
$n (
1 ..
100)
{

if ((
$n %
3) !=
0)
    {

print
$n,
"
\n
";
    }
}

Written by Shlomi Fish