Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: how do i sort hash by key numerically

by arhuman (Vicar)
on Mar 07, 2001 at 13:51 UTC ( [id://62700]=note: print w/replies, xml ) Need Help??


in reply to how do i sort hash by key numerically

for $key ( sort {$a<=>$b} keys %hash) { print "($key)->($hash{$key})\n"; }

Replies are listed 'Best First'.
Re: Answer: how do i sort hash by key numerically
by arhuman (Vicar) on Mar 07, 2001 at 14:01 UTC
    I've set {$a<=>$b} to show you how to change the way the list should be sorted...
    You could sort on :
    key decreasing order : {$b<=>$a}
    values-> {$hash{$a}<=>$hash{$b}}
    key length -> {length{$a}<=>length{$b}}
    or whatever...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-03-28 20:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found