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
| Numeric | String | Meaning |
|---|---|---|
> | gt | Greater than |
>= | ge | Greater than or equal to |
< | lt | Less than |
<= | le | Less 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 numeric Unicode codepoint order of each character in the string.
With a locale declaration, the collation order specified by the locale is
used. These legacy, locale-based collation mechanisms do not interact well
with the Unicode collation mechanisms provided by the Unicode::Collate and Unicode::Collate::Locale modules. It is better to use the modules, not locales.
Codepoint order is not alphabetic order except in (unicameral) ASCII, so
Perl’s string operators will produce alphabetic results only on legacy
ASCII data, not on arbitrary text.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access