in reply to regexp list return 5.6 vs 5.8
Is the behavior of list slice subroutine return an intended feature
A slice is not an array. What you return is what you get. I don't see any magic there. You're definitely right about not golfing production code. This is from a test script however - I allow myself a little more relaxed way of coding in those. :-)
I think I understand the thing now - it's an XY case if I'm correct. That subroutine's return value has been assigned to a scalar and that has been pushed to an array. Maybe this code works differently on 5.6?
sub is_digits { my @rv = $_[0] =~ /^([0-9]+)$/; return @rv[ 0 .. $#rv ]; } my $nothing = is_digits('abc'); my @arr1 = ($nothing); my @arr2 = ('some', 'thing'); push @arr2, @arr1; print "There are ", scalar(@arr2), " elements in \@arr2\n"; print '$arr2[2] is ', defined($arr2[2])?'':'un', "defined\n";
What I expect and get on 5.8.8 is:
There are 3 elements in @arr2 $arr2[2] is undefined
Update: Modified the code to more closely follow the original.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: regexp list return 5.6 vs 5.8
by shmem (Chancellor) on Jan 24, 2008 at 11:13 UTC | |
by Sixtease (Friar) on Jan 24, 2008 at 11:37 UTC | |
by shmem (Chancellor) on Jan 24, 2008 at 12:10 UTC | |
by hipowls (Curate) on Jan 24, 2008 at 11:43 UTC | |
by ikegami (Patriarch) on Jan 24, 2008 at 18:29 UTC | |
by Sixtease (Friar) on Jan 24, 2008 at 12:36 UTC | |
by shmem (Chancellor) on Jan 24, 2008 at 12:48 UTC | |
by Errto (Vicar) on Jan 24, 2008 at 15:59 UTC | |
|
Re^2: regexp list return 5.6 vs 5.8
by hipowls (Curate) on Jan 24, 2008 at 10:34 UTC |