determined by the type of the right operand). Note that the smart match
implicitly dereferences any non-blessed hash or array ref, so the "Hash"
and "Array" entries apply in those cases. (For blessed references, the
-"Any" entry apply.)
+"Object" entries apply.)
$a $b Type of Match Implied Matching Code
====== ===== ===================== =============
Any undef undefined !defined $a
- Any Object invokes ~~ overloading on $object, or dies
+ Any Object invokes ~~ overloading on $object, or dies
Hash CodeRef sub truth for each key[1] !grep { !$b->($_) } keys %$a
Array CodeRef sub truth for each elt[1] !grep { !$b->($_) } @$a
Any CodeRef scalar sub truth $b->($a)
- Hash Hash hash keys identical [sort keys %$a]~~[sort keys %$b]
+ Hash Hash hash keys identical (every key is found in both hashes)
Array Hash hash slice existence grep { exists $b->{$_} } @$a
Regex Hash hash key grep grep /$a/, keys %$b
undef Hash always false (undef can't be a key)
Array Regex array grep grep /$b/, @$a
Any Regex pattern match $a =~ /$b/
+ Object Any invokes ~~ overloading on $object, or falls back:
Any Num numeric equality $a == $b
Num numish[4] numeric equality $a == $b
Any Any string equality $a eq $b
-
1 - empty hashes or arrays will match.
2 - that is, each element smart-matches the element of same index in the
other array. [3]
You can change the way that an object is matched by overloading
the C<~~> operator. This trumps the usual smart match semantics.
-See L<overload>. Since smart matching dispatch is driven by the
-right hand side argument, overloading applies only when the object
-is on the right of C<~~>.
+See L<overload>.
It should be noted that C<~~> will refuse to work on objects that
don't overload it (in order to avoid relying on the object's