Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: regexp list return 5.6 vs 5.8

by ikegami (Patriarch)
on Jan 24, 2008 at 18:12 UTC ( [id://664108]=note: print w/replies, xml ) Need Help??


in reply to regexp list return 5.6 vs 5.8

In scalar context, I get the same behaviour in 5.6.0, 5.6.1, 5.8.0 and 5.8.8

>c:\progs\perl560\bin\perl -wle"$s = sub { my @rv = $_[0] =~ /^([0-9]+ +)$/; retur n @rv[0 .. $#rv]; }->('abc'); print $s" Use of uninitialized value in print at -e line 1. >c:\progs\perl561\bin\perl -wle"$s = sub { my @rv = $_[0] =~ /^([0-9]+ +)$/; retur n @rv[0 .. $#rv]; }->('abc'); print $s" Use of uninitialized value in print at -e line 1. >c:\progs\perl580\bin\perl -wle"$s = sub { my @rv = $_[0] =~ /^([0-9]+ +)$/; retur n @rv[0 .. $#rv]; }->('abc'); print $s" Use of uninitialized value in print at -e line 1. >c:\progs\perl588\bin\perl -wle"$s = sub { my @rv = $_[0] =~ /^([0-9]+ +)$/; retur n @rv[0 .. $#rv]; }->('abc'); print $s" Use of uninitialized value in print at -e line 1.

In list context, I get the same behaviour in 5.6.0, 5.6.1, 5.8.0 and 5.8.8

>c:\progs\perl560\bin\perl -wle"@a = sub { my @rv = $_[0] =~ /^([0-9]+ +)$/; retur n @rv[0 .. $#rv]; }->('abc'); print @a" >c:\progs\perl561\bin\perl -wle"@a = sub { my @rv = $_[0] =~ /^([0-9]+ +)$/; retur n @rv[0 .. $#rv]; }->('abc'); print @a" >c:\progs\perl580\bin\perl -wle"@a = sub { my @rv = $_[0] =~ /^([0-9]+ +)$/; retur n @rv[0 .. $#rv]; }->('abc'); print @a" >c:\progs\perl588\bin\perl -wle"@a = sub { my @rv = $_[0] =~ /^([0-9]+ +)$/; retur n @rv[0 .. $#rv]; }->('abc'); print @a"

Replies are listed 'Best First'.
Re^2: regexp list return 5.6 vs 5.8
by almut (Canon) on Jan 24, 2008 at 19:15 UTC

    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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://664108]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2024-03-28 10:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found