On the other hand, I find the distinction made in the current context between a literal list and an array variable having the same list as value counterintuitive and it is the first time I have tripped over such a distinction in Perl. I never thought of the last element of a list to represent in some way the value of the list, which obviously happens in the smart match context as shown in almut's last example.
I played a little more around with this and found that such a distinction is not made in case we are dealing with array references:
results in the following output:use feature qw / say /; sub check_match { $n++; my $expr = shift; say ("$n th match" . (eval($expr) ? ' succeeds' : ' fails')); } @a = (1, 17, 4); check_match('@a ~~ 17'); check_match('(1, 17, 4) ~~ 17'); $b = [1, 17, 4]; check_match('$b ~~ 17'); check_match('[1, 17, 4] ~~ 17');
Now I am really puzzled, I would find it more natural if either both of cases 2 and 4 succeeded or both failed.1 th match succeeds 2 th match fails 3 th match succeeds 4 th match succeeds
In reply to Re^2: Smart match operator support in Strawberry perl 5.10.0.1 (array vs. list)
by jds17
in thread Smart match operator support in Strawberry perl 5.10.0.1
by jds17
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |