Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: sorting a hash by value with ties

by ikegami (Patriarch)
on Jan 07, 2008 at 11:31 UTC ( [id://660801]=note: print w/replies, xml ) Need Help??


in reply to sorting a hash by value with ties

Well, you can't sort a hash. Presumably you are sorting the keys of the hash?
my @ordered_keys = sort { $hash{$a} cmp $hash{$b} # by value, then || $a cmp $b # by key } keys %hash; foreach my $key (@ordered_keys) { print("$key: $hash{$key}\n"); }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-23 23:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found