Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: regexp list return 5.6 vs 5.8

by almut (Canon)
on Jan 24, 2008 at 19:15 UTC ( #664121=note: print w/replies, xml ) Need Help??


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...)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://664121]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2020-10-23 23:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (241 votes). Check out past polls.

    Notices?