Relational Operators

Perl has two classes of relational operators. One class operates on numeric values, the other on string values, as shown in Table 3.5.

Table 3-5. Relational Operators

NumericStringMeaning
>gtGreater than
>=geGreater than or equal to
<ltLess than
<=leLess than or equal to

These operators return 1 for true and "" for false. Note that relational operators are nonassociating, which means that $a < $b < $c is a syntax error.

In the absence of locale declarations, string comparisons are based on the ASCII/Unicode collating sequences, and, unlike in some computer languages, trailing spaces count in the comparison. With a locale declaration, the collation order specified by the locale is used. (Locale-based collation mechanisms may or may not interact well with the Unicode collation mechanisms currently in development.)

Get Programming Perl, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.