On Wed, Feb 13, 2002 at 02:08:23PM +0100, Jon wrote:
> Frank wrote:
> > 
> > On Wed, Feb 13, 2002 at 01:17:50PM +0100, Andrea wrote:
> > > In article <[EMAIL PROTECTED]> wrote 
>"Jeff 'Japhy' Pinyan"
> > > <[EMAIL PROTECTED]>:
> > >
> > > >>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?
> > >
> > > Don't think about it,
> > > just use the CPAN module List::Util.
> > >
> > > Then you only have to write
> > > my $max = max @values;
> > ---end quoted text---
> > 
> > or:
> > $max= (sort @values)[-1];
> 
> That doesn't seems like a good sollution,
> 
> @a = (-1, -5, -3);
> $max= (sort @a)[-1];
> 
> gives -5 as max, it is max min but not max :)

Yeah, my bad.. I shoulda tested it:
$max=(sort{$a<=>$b}@a)[-1];

sort's default is a lexical comparison, need specify numeric.
me-- for impulse replying ;)

> > 
> > Personally, I'd prefer Japhy's method for efficiency.
> same here, it's straightforward
Yep, it's a good algorithm and it's clear what it does in any language.

-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to