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

Re: finding max value

Thread Previous | Thread Next
From:
Jeff 'japhy' Pinyan
Date:
February 12, 2002 18:18
Subject:
Re: finding max value
Message ID:
Pine.GSO.4.21.0202122117250.11490-100000@crusoe.crusoe.net
On Feb 12, Hans Holtan said:

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

-- 
Jeff "japhy" Pinyan      japhy@pobox.com      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


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