Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
XP is just a number
 
PerlMonks  

Re: Sorting hashes with new value detection

by serf (Chaplain)
on Jan 24, 2006 at 18:25 UTC ( #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"; }


Comment on Re: Sorting hashes with new value detection
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2014-04-23 23:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (557 votes), past polls