Henry Law
2021-11-27 16:34:31 UTC
I have an array of arrayrefs with this structure:
@array = ( [ '20100403', 'text', 'account code' ],
[ '19990503', 'text', 'other account code' ],
... etc )
I want to sort by account code and then by date. I read in various
places that the following will do the trick:
@array = sort { $a->[2] cmp $b->[2] || $a->[0] <=> $b->[0] } @array;
But I'm not getting the sort order I want. I know that the "sort"
function requires a three-valued return from the block, -1, 0 or +1; but
the "||" operator won't do that; it returns TRUE or FALSE.
Is that understanding correct? Is that the reason that I'm not getting
the order I want?
@array = ( [ '20100403', 'text', 'account code' ],
[ '19990503', 'text', 'other account code' ],
... etc )
I want to sort by account code and then by date. I read in various
places that the following will do the trick:
@array = sort { $a->[2] cmp $b->[2] || $a->[0] <=> $b->[0] } @array;
But I'm not getting the sort order I want. I know that the "sort"
function requires a three-valued return from the block, -1, 0 or +1; but
the "||" operator won't do that; it returns TRUE or FALSE.
Is that understanding correct? Is that the reason that I'm not getting
the order I want?
--
Henry Law n e w s @ l a w s h o u s e . o r g
Manchester, England
Henry Law n e w s @ l a w s h o u s e . o r g
Manchester, England