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

Re: finding max value

Thread Previous | Thread Next
Jeff 'japhy' Pinyan
February 12, 2002 18:18
Re: finding max value
Message ID:
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
RPI Acacia brother #734
** 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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About