Numerical Comparison Operators

Contents | Up | Prev | Next

# 7.1. Numerical Comparison Operators

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

`$a == $b` | `$a` and `$b` are equal.
`$a > $b` | `$a` is greater than `$b`
`$a < $b` | `$a` is lesser than `$b`
`$a >= $b` | `$a` is greater or equal to `$b`
`$a <= $b` | `$a` is lesser or equal to `$b`
`$a != $b` | `$a` is not equal to `$b`

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 divisable by 3:

    for $a (1 .. 100)
    {
        if (($a % 3) != 0)
        {
            print $a,"\n";
        }
    }

Contents | Up | Prev | Next