Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Sorting by Value

by simeon2000 (Monk)
on Jul 19, 2002 at 15:57 UTC ( [id://183283]=note: print w/replies, xml ) Need Help??


in reply to Sorting by Value

As far as writing out the solution for you, I will not for I am having a hard time deciphering your post in the first place.

However, sorting a hash in reverse by value as opposed to by key is as simple as:

my %hash = ( 'A' => 5, 'B' => 4, 'C' => 3, 'D' => 2, 'E' => 1 ); for my $key (sort { $hash{$b} <=> $hash{a} } keys %hash) { #... }

I believe will give you the desired effect. Try perldoc -q sort on the command line for more details.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2024-04-25 07:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found