Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
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 drinking their drinks and smoking their pipes about the Monastery: (13)
As of 2015-07-30 17:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (273 votes), past polls