RMGir has asked for the wisdom of the Perl Monks concerning the following question:
If you answered "{2,3,2}, of course", you'd be right, but only if you're using 5.8.0 or better.perl -w -e'; @a=(split / /,"1 2 3 4 5")[1,2,1]; print "{",(join ",",@a +),"}\n";'
Under 5.6.1, that prints "{2,3,}".
It behaves as if the list resulting from the split is some strange heisenbergian construct, where looking at a value destroys it.
Using 1,2,3 as an index list works, but re-using any index returns undef for the 2nd time it appears.
It IS fixed in 5.8.0, but I thought I should warn any fellow monks who might still be in 5.6.1 of this oddity...
EDIT: The behaviour isn't limited to split, either. This has the same problem:
perl -e'$x="1 2 3 4 5"; @a=($x=~/\d+/g)[1,2,1]; print "{",(join ",",@a +),"}\n";'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Interesting (split) oddity with 5.6.1, fixed in 5.8.0
by BrowserUk (Patriarch) on Oct 17, 2003 at 20:02 UTC | |
|
Re: Interesting (split) oddity with 5.6.1, fixed in 5.8.0
by Nkuvu (Priest) on Oct 17, 2003 at 18:57 UTC | |
by RMGir (Prior) on Oct 17, 2003 at 19:16 UTC | |
|
Re: Interesting (split) oddity with 5.6.1, fixed in 5.8.0
by kleucht (Beadle) on Oct 21, 2003 at 01:08 UTC |