To sort on more than one key, i'd probably do something like this:@sorted = sort {$$a{"key"} <=> $$b{"key"} } @unsorted;
A function would be prettier...@sorted = sort {$$a{"least_signifigant_key"} <=> $$b{"least_signifigan +t_key"}} @unsorted; [...] @moresorted = sort{$$a{"most_signifigant_key"} <=> $$b{"most_signifiga +nt_key"}} @sorted;
--seansub multi_key_sort { # pass me two references to arrays my $array = shift; # the first to the array that needs sorting.. my $keys = shift; # the second to an array of keys to sort by for my $key (@$keys) { @$array = sort {$$a{$key} cmp $$b{$key}} @$array; } return @$array; } my @sorted_array = &multi_key_sort(\@unsorted_array,\@array_of_keys); # @array_of_keys in order from least to most signifigant
In reply to Re: Sort Array of Hashes based on Hash value
by sean
in thread Sort Array of Hashes based on Hash value
by raflach
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |