Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
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"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://525275]
help
Chatterbox?
[shmem]: but I'm crumbling smaller stones. remember...
[stevieb]: I'm working on it to fatten it up and make it more reliant so I can finalize my Raspberry Pi automated build system for that software :) It's all well and fun, until I try to make it work with Windows lol
[shmem]: "debugging a program is more difficult than to write it in the first place. If you code your program as smart as you are, you are, by definition, too dumb to debug it."
[stevieb]: I literally laughed. That's good :) Perhaps I just need to go climb another mountain and forget about it
shmem seeks a tate and smikes a pope

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2017-03-28 22:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (342 votes). Check out past polls.