Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: sorting a hash

by mickeyn (Priest)
on Feb 28, 2006 at 12:52 UTC ( #533333=note: print w/ replies, xml ) Need Help??


in reply to sorting a hash

From your expected output you probably meant sorting the keys and not the values of the hash.

foreach ( sort {$b <=> $a} keys %hash ){ print $_," ",$hash{$_},"\n"; }
should answer your question (decending numeric key sorting).

Enjoy,
Mickey


Comment on Re: sorting a hash
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (10)
As of 2015-07-04 06:22 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 (58 votes), past polls