Don't use something that alters
@array on the left side of the same assignment as accessing
@array on the right. Order of execution is not guaranteed. And your taking a reference to a dereference of a reference made from a list constructed from something that was already a list (whew!) has me dizzy.
Also, learn to use the shortcuts of CGI.pm. Even Lincoln avoids the object-oriented form for short programs.
Some code:
my @array = qw(1 2 3 4 5 6 7 8 9);
my %test;
my $where = shift @array;
$test{$where} = [splice @array, 0, 2];
...
Don't put the shift in the same expresssion as the splice. Order of execution
not guaranteed. One other way to do it:
$test{$_} = [splice @array, 0, 2] for shift @array;
which is nice because it eliminates the intermediate variable. Even weirder:
$_ = [splice @array, 0, 2] for $test{shift @array};
which still works because we know the shift has to happen before the splice.
-- Randal L. Schwartz, Perl hacker
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.