@v=((grep { $_ <= $pivot } @$v), (grep { $_ > $pivot } @$v));
is that what you intended?
I suppose that what you really want is to mimic the sort on the original post but numerically: sort first the elements > $pivot and then the rest.
Then, for your specific data, integers between -100 and 100, this works:
my @v=nkeysort { $_<$pivot ? $_ + 200 : $_ } @$v;
but if you know nothing about the numbers in $@v, then figuring a convenient sorting key can be quite difficult, it's easier to just use a grep/sort combination:
my @v=((sort {$a<=>$b} (grep { $_ >= $pivot } @$v)),
(sort {$a<=>$b} (grep { $_ < $pivot } @$v)));
that inserted on the outer sort becomes:
my @sorted = nkeysort {
( ( sort {$a<=>$b} (grep { $_ >= $pivot } @$_) ),
( sort {$a<=>$b} (grep { $_ < $pivot } @$_) ) )[50]
} @data;
BTW, note that for numeric keys you have to use nkeysort.
|