Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Sorting hashes with new value detection

by serf (Chaplain)
on Jan 24, 2006 at 18:25 UTC ( [id://525275]=note: print w/replies, xml ) Need Help??


in reply to Sorting hashes with new value detection

If you wanted to do it using map you could do this:
my %hash; map { push( @{ $hash{ $values{$_} } }, $_ ) } keys %values;
which if you were golfing would save you a few characters on Roy Johnson's probably easier to read version:
while(my($k,$v)=each%values){push@{$hash{$v}},$k;}
which becomes:
map{push(@{$hash{$values{$_}}},$_)}keys%values;
and then access the result with:
for my $key (reverse sort keys %hash) { print "Level $key:\n", join(", ", @{$hash{$key}}), "\n\n"; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-24 22:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found