in reply to How to get 2nd highest value from an array?

use warnings; use strict; my @list = (4, 7, 1, 3, 2, 9); my $second = (sort @list)[-2]; print $second;

Prints:

7

DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: How to get 2nd highest value from an array?
by Fletch (Bishop) on Dec 14, 2005 at 00:42 UTC

    Of course if @list has only one element you may get an unexpected result . . . :)