"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$x and $y are equal.
$x > $y$x is greater than $y
$x < $y$x is lesser than $y
$x >= $y$x is greater or equal to $y
$x <= $y$x is lesser or equal to $y
$x != $y$x is 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