in reply to my array is almost a hash, but keys are not unique.
If you eschew the C for loop where possible, and don't mind destroying the source array, then you can:
use strict; use warnings; use Data::Dump::Streamer; my @in = (one => 1, two => 2, two => '2.003'); my %hash; while (@in > 1) { my ($key, $value) = splice @in, 0, 2; push @{$hash{$key}}, $value; } Dump \%hash;
Prints:
$HASH1 = { one => [ 1 ], two => [ 2, 2.003 ] };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: my array is almost a hash, but keys are not unique.
by Boldra (Curate) on Apr 07, 2009 at 14:20 UTC | |
by GrandFather (Saint) on Apr 07, 2009 at 20:20 UTC |