Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: regexp list return 5.6 vs 5.8

by parv (Vicar)
on Jan 24, 2008 at 09:08 UTC ( #663966=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

Do you really get [[] in the first print statement? If so, any idea how (output of first 2 print's is [] with perl 5.8.7 on CentOS 5)?

Replies are listed 'Best First'.
Re^3: regexp list return 5.6 vs 5.8
by hipowls (Curate) on Jan 24, 2008 at 09:34 UTC

    Really, I too was surprised. Changing sub test to

    sub test { my @rv = $_[0] =~ /^([0-9]+)$/; print "<<@rv>>\n"; return @rv[ 0 .. $#rv ]; }
    produced
    <<>> [[] <<>> [] <<123>> [123] <<123>> [123]
    changing sub test to
    sub test { my @rv = $_[0] =~ /^([0-9]+)$/; print "<<@rv>>\n"; return wantarray? @rv: $rv[-1]; }
    produces
    michael$ perl t.pl <<>> Use of uninitialized value in print at t.pl line 5. [] <<>> [] <<123>> [123] <<123>> [123]
    Note the warning. (And I suspect there are some monks who are now saying I told you so;-)

      Wow, so the [[] was not a typo? I thought it was. I still don't understand how it could have got there! What does it print when you use different delimiters? (like print "{", scalar(test('abc')), "}";)

      use strict; use warnings; print "Just Another Perl Hacker\n";

        Strange indeed.

        michael$ perl t.pl {{} {} {123} {123}

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2020-10-20 06:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (209 votes). Check out past polls.

    Notices?