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?<
Ofcourse, if you want both the maxium and minimum value of a list at the same time, it is more efficient to fetch both at once; it only has to perform 3 order comparisons per 2 items of data, rather than 4. This may matter if the data sets are big enough.
List::Util
doesn't provide a minmax
function but List::MoreUtils
does.
use strict;
use warnings;
use feature qw( say );
use List::MoreUtils qw( minmax );
my ( $min, $max ) = minmax @data;
say $min;
say $max;