awohld has asked for the wisdom of the Perl Monks concerning the following question:
I want to take my %hash and create a new %new_hash out of it.
I need to swap the key with the first array element that the has points to.
In so I want to %hash to go from:
to the new %new_hash:$hash{'one'} = [ '1', 'two', 'three']; $hash{'two'} = [ '2', 'three', 'four']; $hash{'three'} = [ '3', 'four', 'five'];
Here is my example script;$hash{'1'} = [ 'one', 'two', 'three']; $hash{'2'} = [ 'two', 'three', 'four']; $hash{'3'} = [ 'three', 'four', 'five'];
#!/usr/bin/perl -w use strict; use Data::Dumper; my %hash; $hash{'one'} = [ '1', 'two', 'three']; $hash{'two'} = [ '2', 'three', 'four']; $hash{'three'} = [ '3', 'four', 'five']; # Here is where I can't get 'map' quite right my %new_hash = map { $_->[0] => [ getkey($_), $_->[1], $_->[2] ] }; print Dumper \%new_hash;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using MAP to swap around HoA hash keys and array values.
by ysth (Canon) on Jun 11, 2006 at 19:56 UTC | |
|
Re: Using MAP to swap around HoA hash keys and array values.
by planetscape (Chancellor) on Jun 11, 2006 at 20:26 UTC | |
|
Re: Using MAP to swap around HoA hash keys and array values.
by ambrus (Abbot) on Jun 11, 2006 at 20:39 UTC | |
by diotalevi (Canon) on Jun 12, 2006 at 00:49 UTC | |
|
Re: Using MAP to swap around HoA hash keys and array values.
by jwkrahn (Abbot) on Jun 11, 2006 at 21:49 UTC |