in reply to List::Util max with block

If you wanted the entire @list in sorted order, the Schwartzian Transform would be what you're looking for:
@sorted_els = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { [$_, complex_calculation($_)] } @list;

I haven't tested the efficiency, but you might want to compare the other solutions with:

# swapped $a/$b to get max ($max_el) = map { $_->[0] } sort { $b->[1] <=> $a->[1] } map { [$_, complex_calculation($_)] } @list;

Replies are listed 'Best First'.
Re^2: List::Util max with block
by ikegami (Patriarch) on Nov 06, 2009 at 21:15 UTC

    Why do you call map { $_->[0] } on every element if you just want one?

    Note that the map EXPR, syntax of map is faster than the map BLOCK syntax.

    And then there's the issue that you've taken an O(N) problem and made it O(N log N) by using sort, which means it doesn't scale as well.