monkfan has asked for the wisdom of the Perl Monks concerning the following question:
Yielding:use Data::Dumper; my @array = ( 0, 1, 2, 3, 4, 5 ); my %uniq; @uniq{@array[1..$#array]} = (); print Dumper \%uniq;
But how can one achieve the same result, if what we have is AoA. I tried the following but doesn't work:$VAR1 = { '4' => undef, '1' => undef, '3' => undef, '2' => undef, '5' => undef };
Which prints the wrong:use Data::Dumper; my %uniq; my @aoa = ( ['foo',0], # Changed from 'AoA' to 'aoa'. Thanks to bobf. ['foo',1], ['foo',2], ['foo',3], ['foo',4], ['foo',5],); @uniq{ @aoa[ 1 ... $#aoa ]->[-1] } = (); print Dumper \%uniq;
$VAR1 = { '5' => undef };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Transforming AoA to Hash by Array Slicing
by rhesa (Vicar) on Aug 08, 2006 at 03:01 UTC | |
|
Re: Transforming AoA to Hash by Array Slicing
by bobf (Monsignor) on Aug 08, 2006 at 03:41 UTC |