in reply to Re: Bring back the smartmatch operator (but with sane semantics this time)!
in thread Bring back the smartmatch operator (but with sane semantics this time)!
The string/number heuristic is responsible for some of the oddest behaviour of smart match. Let's take for example the use of $x ~~ @array as an "in" operator.
sub as_bool { $_[0] ? "true" : "false" } my @greetings = qw( Hi Bye ); say as_bool("Hi" ~~ @greetings); # true say as_bool("Hiya" ~~ @greetings); # false
OK, everything is working as expected so far. Now let's do something a little more complex...
push @greetings, 0, 1; say as_bool(0 ~~ @greetings); # true say as_bool(1 ~~ @greetings); # true say as_bool(2 ~~ @greetings); # false say as_bool("Hiya" ~~ @greetings); # true ?!?!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Bring back the smartmatch operator (but with sane semantics this time)!
by Anonymous Monk on Jun 12, 2014 at 22:14 UTC |