Trick question. What do you think the following prints?
perl -w -e'; @a=(split / /,"1 2 3 4 5")[1,2,1]; print "{",(join ",",@a
+),"}\n";'
If you answered "{2,3,2}, of course", you'd be right, but
only if you're using 5.8.0 or better.
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";'
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.