in reply to Re: Reorganising a Hash for Output
in thread Reorganising a Hash for Output
The trick (imho) is to build the "reverse" hash first
Wrong. What if you have duplicate values in your arrays? You will loose a whole lot of values as they can't exist as "duplicate" hash keys. Oops
my %x = ( 1 => [qw( o o p s )], 2 => [qw( j u s t )], 3 => [qw( a n o t h e r )], 4 => [qw( h a s h )], 5 => [qw( e r r o r )], 6 => [qw( j u s t a n o t h e r p e r l h a c k e r , )] ); my %rev = map { my $key=$_; map { $_=>$key} @{$x{$key}} } keys %x; print "$_ -> $rev{$_}\n" foreach sort keys %rev;
What happened to all the values for keys 1-5?
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
|
---|
In Section
Seekers of Perl Wisdom