Equality Operators
Binary "=="
returns true if the left argument is numerically equal to the right argument.
Binary "!="
returns true if the left argument is numerically not equal to the right argument.
Binary "<=>"
returns -1, 0, or 1 depending on whether the left argument is numerically less than, equal to, or greater than the right argument. If your platform supports NaN
's (not-a-numbers) as numeric values, using them with "<=>"
returns undef. NaN
is not "<"
, "=="
, ">"
, "<="
or ">="
anything (even NaN
), so those 5 return false. NaN != NaN
returns true, as does NaN !=
anything else. If your platform doesn't support NaN
's then NaN
is just a string with numeric value 0.
$ perl -le '$x = "NaN"; print "No NaN support here" if $x == $x' $ perl -le '$x = "NaN"; print "NaN support here" if $x != $x'
(Note that the bigint, bigrat, and bignum pragmas all support "NaN"
.)
Binary "eq"
returns true if the left argument is stringwise equal to the right argument.
Binary "ne"
returns true if the left argument is stringwise not equal to the right argument.
Binary "cmp"
returns -1, 0, or 1 depending on whether the left argument is stringwise less than, equal to, or greater than the right argument.
Binary "~~"
does a smartmatch between its arguments. Smart matching is described in the next section.
"lt"
, "le"
, "ge"
, "gt"
and "cmp"
use the collation (sort) order specified by the current LC_COLLATE
locale if a use
locale
form that includes collation is in effect. See perllocale. Do not mix these with Unicode, only use them with legacy 8-bit locale encodings. The standard Unicode::Collate
and Unicode::Collate::Locale
modules offer much more powerful solutions to collation issues.
For case-insensitive comparisions, look at the fc case-folding function, available in Perl v5.16 or later:
if ( fc($x) eq fc($y) ) { ... }
Please login to continue.