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

Re: sorting hashes

by bichonfrise74 (Vicar)
on Mar 25, 2009 at 01:34 UTC ( [id://752989]=note: print w/replies, xml ) Need Help??


in reply to sorting hashes

If I understand your question... I would write it in this manner.
#!/usr/bin/perl use strict; my %old_hash = ( 'number' => '5', 'cat' => '3', 'dog' => '2' ); my %new_hash = reverse %old_hash; my @sort_arrays = map { $old_hash{$_} } sort { $old_hash{$a} <=> $old_hash{$b} } (keys %old_hash); print "$new_hash{$_} -> $_\n" for (@sort_arrays);

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-25 04:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found