I have an array with values 33, 32, 8, 100.
How can I find the maximum and minimum value in this array?
Do I need to include any special libraries?<
List::Util's min
and max
are fine,
use List::Util qw( min max );
my $min = min @numbers;
my $max = max @numbers;
But List::MoreUtils's minmax
is more efficient when you need both the min and the max (because it does fewer comparisons).
use List::MoreUtils qw( minmax );
my ($min, $max) = minmax @numbers;
List::Util is part of core, but List::MoreUtils isn't.