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

Re: finding max value

Thread Previous | Thread Next
From:
Andrea Holstein
Date:
February 13, 2002 04:33
Subject:
Re: finding max value
Message ID:
pan.2002.02.13.13.17.49.407411.1611@yahoo.de
In article <Pine.GSO.4.21.0202122117250.11490-100000@crusoe.crusoe.net> wrote "Jeff 'Japhy' Pinyan"
<jeffp@crusoe.net>:

>>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;

Greetings,
Andrea

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About