Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: regexp list return 5.6 vs 5.8

by hipowls (Curate)
on Jan 24, 2008 at 09:02 UTC ( [id://663964]=note: print w/replies, xml ) Need Help??


in reply to regexp list return 5.6 vs 5.8

Running this script on Solaris

#!/usr/local/bin/perl -w use strict; print "[", scalar test('abc'), "]\n"; print "[", test('abc'), "]\n"; print "[", scalar test('123'), "]\n"; print "[", test('123'), "]\n"; sub test { my @rv = $_[0] =~ /^([0-9]+)$/; return @rv[ 0 .. $#rv ]; }
produces (5.6.1)
michael$ perl t.pl [[] [] [123] [123] michael:$ perl -v This is perl, v5.6.1 built for sun4-solaris Copyright 1987-2001, Larry Wall Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 source ki +t. Complete documentation for Perl, including FAQ lists, should be found +on this system using `man perl' or `perldoc perl'. If you have access to + the Internet, point your browser at http://www.perl.com/, the Perl Home Pa +ge.
and (5.005_03)
michael$ /usr/local/bin/perl t.pl [[] [] [123] [123] michael$ /usr/local/bin/perl -v This is perl, version 5.005_03 built for sun4-solaris Copyright 1987-1999, Larry Wall Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5.0 source +kit. Complete documentation for Perl, including FAQ lists, should be found +on this system using `man perl' or `perldoc perl'. If you have access to + the Internet, point your browser at http://www.perl.com/, the Perl Home Pa +ge.

There were no warnings, I get them when running under 5.10.0

Replies are listed 'Best First'.
Re^2: regexp list return 5.6 vs 5.8
by parv (Parson) on Jan 24, 2008 at 09:08 UTC

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

      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";

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (6)
As of 2024-03-29 12:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found