2009/7/1 Paul Fenwick <pjf@perltraining.com.au>:
> So, to help fix that, I've written (as I think I promised to long ago), a> test case to find any surprises. =A0It's based upon the smart-match Perl =tip
> at http://perltraining.com.au/tips/2008-04-18.html . =A0I'll send it as a> patch in a separate e-mail. =A0Currently, it gives me two surprises:>> =A0 =A0 =A0 =A0my @foo =3D qw(x y z xyzzy ninja);> =A0 =A0 =A0 =A0ok( @foo ~~ 'ninja' ); =A0 =A0 =A0 =A0 =A0# Fails>> =A0 =A0 =A0 =A0my $array_ref =3D [5, 10, 15];> =A0 =A0 =A0 =A0ok ( $array_ref ~~ 10 ); =A0 =A0 =A0 =A0# Fails>> Looking down the table in blead/perlsyn.pod, I see the first one has a> string on the RHS, and the RHS determines what we do. =A0It looks like th=at
> falls through to the very last rule (Any/Any), which means we're doing> string equality. =A0That doesn't seem very useful; because unless we've> specially crafted our string, it's never going to be true.>> The same seems to apply for the second one. =A0I assume we're triggering> Any/Num, which is doing a straight numerical equality. =A0Again, that doe=sn't
> seem very useful.>> If that's what really what these are triggering, then can I respectfully> suggest they're changed to search the list instead (as they would do if t=hey
> were reversed)?No, because if we have
given ($foo) { when (undef) {...} }
we sort of expect the code in the when clause to be executed when $foo
is not defined.
That's precisely the same reason why in Perl 6 ~~ isn't commutative any
more either.