in reply to Sorting on 2 fields with the same priority

If I understand your problem correctly, you are sorting collections by the lowest value found in each collection

Well, not exactly, I am sorting collections considering 2 values. If the lowest value of 2 collections are the same, I use the higher for untie. In the example I give in the post:

A 15134 135 D 16141345 135

After sorting A will be placed before D because although they have the same lower value (135), A has the lower higher.

You can't do that with List::Util's min, because it only returns the mininum value

citromatik

Replies are listed 'Best First'.
Re^2: Sorting on 2 fields with the same priority
by Limbic~Region (Chancellor) on Feb 08, 2008 at 20:26 UTC
    citromatik,
    I would still avoid sort.
    my @sorted = map $_->[0], sort {$a->[1] <=> $b->[1] || $a->[2] <=> $b->[2]} map { my (undef, $val1, $val2) = split " "; ($val1, $val2) = ($val2, $val1) if $val2 < $val1; [$_, $val1, $val2]; } <DATA>; # Untested

    Cheers - L~R