Equality Operators
The equality operators listed in Table 3.6 are much like the relational operators.
Table 3-6. Equality Operators
| Numeric | String | Meaning |
|---|---|---|
== | eq | Equal to |
!= | ne | Not equal to |
<=> | cmp | Comparison, with signed result |
The equal and not-equal operators return 1
for true and "" for false (just as the relational operators do). The
<=> and cmp operators
return -1 if the left operand is less than the
right operand, 0 if they are equal, and
+1 if the left operand is greater than the right.
Although the equality operators appear to be similar to the relational
operators, they do have a lower precedence level, so $a <
$b <=> $c < $d is syntactically valid.
For reasons that are apparent to anyone who has seen
Star Wars, the <=>
operator is known as the "spaceship" operator.
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