Perl: Sorting a hash

This syntax still doesn't make much sense to me but here is how you sort a perl hash by value. This returns a list of all the keys of the hash sorted in the order you want. To reverse the sort simply change $a and $b locations with each other.

my @sort = sort{ $unique{$a} <=> $unique{$b} } keys %unique;
Leave A Reply - 2 Replies
Replies
Ravindra 2007-01-15 12:17am - No Email - Logged IP: 202.56.245.195

Thanks Man!! Its solved my problem..

Anonymous 2008-12-10 02:47pm - No Email - Logged IP: 144.226.230.36

reversing a and b didnt work for me, however doing a @sort = reverse sort{ ... worked! Thanks

All content licensed under the Creative Commons License