Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Re: Reorganising a Hash for Output

by tachyon (Chancellor)
on May 07, 2002 at 15:13 UTC ( #164672=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://164672]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2022-05-22 16:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (80 votes). Check out past polls.

    Notices?