in reply to Re^3: Custom Sort An AoA
in thread Custom Sort An AoA
something like
sub cmp_vec { # return either -1,0 or 1 comparing over two equally sized arrays } sort { @$a <=> @$b or cmp_vec($a,$b) } @list;
for full flexibility a cmp-function could be passed as call-back in third position.
As a side note, I'm not sure if this could be done with Perl6 Meta ops, something like @a >>cmp<< @b (after reversing of course).
Cheers Rolf
( addicted to the Perl Programming Language)
something like
sub cmp_vec { my ($a,$b) = @_; for (reverse 0.. @$a-1) { if (my $x= $a->[$_] cmp $b->[$_]) { return $x } } return 0; ]
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: Custom Sort An AoA
by Limbic~Region (Chancellor) on Apr 02, 2014 at 12:11 UTC |