Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

RE: RE: Re: Sort Array of Hashes based on Hash value

by BBQ (Curate)
on Jun 07, 2000 at 09:22 UTC ( [id://16819]=note: print w/replies, xml ) Need Help??


in reply to RE: Re: Sort Array of Hashes based on Hash value
in thread Sort Array of Hashes based on Hash value

I like the example from perlfaq4:
Here we'll do a reverse numeric sort by value, and if two keys are identical, sort by length of key, and if that fails, by straight ASCII comparison of the keys (well, possibly modified by your locale -- see perllocale). @keys = sort { $hash{$b} <=> $hash{$a} || length($b) <=> length($a) || $a cmp $b } keys %hash;
as our peers above have pointed out ($$a{$key}) does the work in your case, but the idea of or'ing with a final cmp will probably get better results when you can't tell what's in those arrays.

#!/home/bbq/bin/perl
# Trust no1!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-26 06:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found