in reply to Re: Smart match operator support in Strawberry perl 5.10.0.1 (array vs. list)
in thread Smart match operator support in Strawberry perl 5.10.0.1

Hi, thanks for your replies, did not have time to check them up to now! So it seems like I don't need to say "use feature '~~';" at all, that's o.k.

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:

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');
results in the following output:
1 th match succeeds 2 th match fails 3 th match succeeds 4 th match succeeds
Now I am really puzzled, I would find it more natural if either both of cases 2 and 4 succeeded or both failed.