bradcathey has asked for the wisdom of the Perl Monks concerning the following question:
Fellow Monasterians,
I'm trying to sort an AoH first by one key and then another 'under' that. So:
my $sqldata = [ { 'under' => '2', 'order' => '2' }, { 'under' => '2', 'order' => '1' }, { 'under' => '1', 'order' => '2' }, { 'under' => '1', 'order' => '3' }, { 'under' => '1', 'order' => '1' } ]; my $AoH = [ sort { $a->{under} <=> $b->{under} } @$sqldata ];
and I want to end up with:
my $sqldata = [ { 'under' => '1', 'order' => '1' }, { 'under' => '1', 'order' => '2' }, { 'under' => '1', 'order' => '3' }, { 'under' => '2', 'order' => '1' }, { 'under' => '2', 'order' => '2' } ];
I thought I had found it in sorting a hash by keys, according to preference, but that appears to be a different deal. Thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sorting AoH by two keys
by nothingmuch (Priest) on Jul 08, 2005 at 21:41 UTC | |
by bradcathey (Prior) on Jul 08, 2005 at 22:19 UTC | |
by tphyahoo (Vicar) on Jul 09, 2005 at 16:19 UTC | |
|
Re: Sorting AoH by two keys
by tphyahoo (Vicar) on Jul 09, 2005 at 16:28 UTC |