in reply to Elegance, dammit!
In real life, I would normally use a splice like Errto and jdporter.
Before *any* solution, I would put:
die if @ref / 3;
Most elegant, non-destructive Perl5 solution I could think of:
my %out = map { $ref[$_] => [ @ref[$_+1..$_+2] ] } grep { not $_ % 3 } 0 .. $#ref;
Even better, but requires Perl6:
for @ref -> $key, $val1, $val2 { %out{$key} = [ $val1, $val2 ]; }
Update: Better yet, this also works in Perl6:
my %out = map -> $k, $v, $w { $k => [ $v, $w ]; }, @ref;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Elegance, dammit!
by oko1 (Deacon) on Jun 16, 2007 at 02:58 UTC | |
|
Re^2: Elegance, dammit!
by moritz (Cardinal) on Jun 16, 2007 at 09:10 UTC | |
|
Re^2: Elegance, dammit!
by kyle (Abbot) on Jun 16, 2007 at 19:30 UTC |