I needed to sort an array of hashes in Perl (actually, it was an arrayref of hashrefs). A quick Google search led me to this page:
http://www.storm-consultancy.com/blog/development/code-snippets/perl-sorting-an-array-of-hashes/
With a little modification of the example, I had something that worked perfectly:
my @{ $sorted } = sort { $b->{key_field} <=> $a->{key_field} } @{ $data };
http://www.storm-consultancy.com/blog/development/code-snippets/perl-sorting-an-array-of-hashes/
With a little modification of the example, I had something that worked perfectly:
my @{ $sorted } = sort { $b->{key_field} <=> $a->{key_field} } @{ $data };
No comments:
Post a Comment