in reply to my array is almost a hash, but keys are not unique.
50 lines? What language? A slightly more efficient option:
my $in = [ one => 1, two => 2, two => '2.003' ]; my $out = {}; for(my $i=0; $i<$#$in; $i+=2) { push @{$out->{$in->[$i]}}, $in->[$i+1]; }
or for a game of golf
my $i=0; push(@{$out->{$in->[$i++]}},$in->[$i++]) while $i<$#$in;
Best, beth
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: my array is almost a hash, but keys are not unique.
by Boldra (Curate) on Apr 03, 2009 at 08:40 UTC | |
|
Re^2: my array is almost a hash, but keys are not unique.
by GrandFather (Saint) on Apr 06, 2009 at 02:37 UTC | |
by ELISHEVA (Prior) on Apr 06, 2009 at 04:57 UTC | |
by GrandFather (Saint) on Apr 06, 2009 at 20:43 UTC | |
by ELISHEVA (Prior) on Apr 07, 2009 at 01:30 UTC | |
by Boldra (Curate) on Apr 07, 2009 at 14:50 UTC |