http://qs321.pair.com?node_id=664121


in reply to Re: regexp list return 5.6 vs 5.8
in thread regexp list return 5.6 vs 5.8

I think whether you get different behaviour depends on the exact circumstances in which the evaluation happens. I would argue that you don't see a difference, because there's nothing "on the stack" (as I hypothesized in my other reply) prior to the evaluation of the slice in scalar context. If I modify your test slightly, I do get different results depending on Perl version.

perl -wle'sub {"foo"}->(), $s = sub { my @rv = $_[0] =~ /^([0-9]+)$/; +return @rv[0 .. $#rv]; }->("abc"); print $s'

5.8.4 prints foo (and no warning), while 5.8.8 and 5.10.0 print Use of uninitialized value $s in print at -e line 1. (and no "foo").

Note 1: the sub {"foo"}->() is just a way to avoid the "Useless use of a constant in void context", which I would otherwise get when simply writing "foo", ...

Note 2: Windows users will probably have to swap single and double quotes  (I changed them myself in the first place, because ikegami's original version would have required additional quoting with a typical Unix shell...)