in reply to Numeric Sorting on Characters

Probably the ternary operator to the rescue:

sort { ($passes->{$a}->{'cpu'} ne '-' ? $passes->{$a}->{'cpu'} : 0) <=> ($passes->{$b}->{'cpu'} ne '-' ? $passes->{$b}->{'cpu'} : 0) } keys %{$passes}

UPDATE: In addition to choroba's solution you're able to assign a different value in case of '-'.

McA

Replies are listed 'Best First'.
Re^2: Numeric Sorting on Characters
by AnomalousMonk (Archbishop) on Aug 14, 2013 at 23:10 UTC

    Another ternary approach that gathers  '-' elements to the lowest indices of the output array regardless of the numeric value of any other elements to be sorted, e.g., negative values.

    >perl -wMstrict -le "my @unsorted = (1, 10, '-', 2, -3, 20, '-', '-', 3, 0, 2, 11, 8, 7); ;; my @sorted = sort numeric_ascending_with_dash_leftmost @unsorted; print qq{@sorted}; ;; @sorted = sort { -numeric_ascending_with_dash_leftmost() } @unsorted; print qq{reversed: @sorted}; ;; print qq{still unsorted: @unsorted}; ;; sub numeric_ascending_with_dash_leftmost { return $a eq '-' ? -1 : $b eq '-' ? 1 : $a <=> $b ; } " - - - -3 0 1 2 2 3 7 8 10 11 20 reversed: 20 11 10 8 7 3 2 2 1 0 -3 - - - still unsorted: 1 10 - 2 -3 20 - - 3 0 2 11 8 7