in reply to Sorting AoH by two keys
This works because || evaluates it's left side, and if it's false (0 is false), it evaluates the right too. It returns the first true value it finds (or the last false one if it didn't).my $AoH = [ sort { $a->{under} <=> $b->{undef} || $a->{order} <=> $b->{order} } @$sqldata ];
Let's compare 2,2 and 2,1:
(2 <=> 2) == 0 so 0 || 2 <=> 1 evaluates to 2 <=> 1 (2 <=> 1) == 1 # the answer we wanted
BTW, I noticed you have 'sqldata'... This smells like you're doing fetching the entire result table as an array ref, and then sorting it... Why not make it into
This stuff is better (and probably more efficiently) handled on the server side.select ... order by under, order;
Update: tphyahoo was right - but it was no typo... I wrote down $a twice when I should have written $b. Sorry!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sorting AoH by two keys
by bradcathey (Prior) on Jul 08, 2005 at 22:19 UTC | |
|
Re^2: Sorting AoH by two keys
by tphyahoo (Vicar) on Jul 09, 2005 at 16:19 UTC |