develooper Front page | perl.beginners | Postings from February 2002

Re: finding max value

Thread Previous | Thread Next
Andrea Holstein
February 13, 2002 04:33
Re: finding max value
Message ID:
In article <> wrote "Jeff 'Japhy' Pinyan"

>>I have a set of functions that give numeric results, and I need to compare  them and choose the
>>maximal value. Is there any simple way of finding max?
> Go through them one at a time, and keep track of the largest value:
>   my $max = $values[0];
>   for (@values) {
>     $max = $_ if $_ > $max;
>   }

Don't think about it,
just use the CPAN module List::Util.

Then you only have to write 
my $max = max @values;


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About