in reply to How do I find the biggest number in an array of numbers.

If what you need is not just the biggest element but the N biggest elements, you can use Sort::Key::Top:
use Sort::Key::Top qw(rntop ntop); my $n = 5; my @data = (1, 30, 4, 5, 12, -12, 4.1, ...); my @min_n = ntop $n => @data; my @max_n = rntop $n => @data;

Replies are listed 'Best First'.
Re: Answer: How do I find the biggest number in an array of numbers.
by Skeeve (Parson) on May 27, 2007 at 18:45 UTC

    I didn't look at the module, but tell me: What's wrong with this:

    my $n = 5; my @data = (1, 30, 4, 5, 12, -12, 4.1, 18,20, 2, 0 ,4, 36, 0, 8, 15, 4 +2, 4711, 0xdead, 0xbeef); my @top5= (sort { $b <=> $a } @data)[0..$n-1]; print join "\n",@top5,'';

    s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
    +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e