Re: max/min

2002-04-12 Thread Elias Assmann
On Fri, 12 Apr 2002, Jonathan E. Paton wrote: > Yes, it should be optimised away, but why would you do it in the first place? If > you tell it to do something, then why should it shy away from doing what it was > told? Optimising things that don't occur in everyday programming is a waste of > ti

Re: max/min

2002-04-12 Thread Jonathan E. Paton
> > > I'm a litttle puzzled as to why max2 (foreach with if modifier) is > > > consistently about 25% faster than max4 (foreach with ternary operator). > > > My guess is that the difference is due to how often the assignment is > > > done. With the if modifier, the assignment is done only when ne

Re: max/min

2002-04-12 Thread Elias Assmann
On Fri, 12 Apr 2002, Jonathan E. Paton wrote: > > I'm a litttle puzzled as to why max2 (foreach with if modifier) is > > consistently about 25% faster than max4 (foreach with ternary operator). > > My guess is that the difference is due to how often the assignment is > > done. With the if modifie

Re: max/min

2002-04-12 Thread Jonathan E. Paton
> >> After I sent this I had a flash of enlightenment: > >>$max = (sort {$a <=> $b} @_)[-1]; > >> May be slower, though, I don't know. > > > > How many times have I seen this? I mean, I've seen > > this construct many times, and the question deserves > > a place in the Perl FAQ. > > How to f

Re: max/min

2002-04-12 Thread Richard J. Barbalace
Jonathan Paton writes: >> After I sent this I had a flash of enlightenment: >>$max = (sort {$a <=> $b} @_)[-1]; >> May be slower, though, I don't know. > > How many times have I seen this? I mean, I've seen > this construct many times, and the question deserves > a place in the Perl FAQ. How

RE: max/min

2002-04-12 Thread Elias Assmann
On Thu, 11 Apr 2002, Bryan R Harris wrote: > > ACK! void use of map! > Huh? Is that "void" or "avoid"? What's wrong with map? void. You're using map in void context here (which means, if I'm not mistaken, you throw the return value away without using it), and this is said to be a Bad Thing (tho

Re: max/min

2002-04-11 Thread Jonathan E. Paton
> After I sent this I had a flash of enlightenment: > >$max = (sort {$a <=> $b} @_)[-1]; > > May be slower, though, I don't know. How many times have I seen this? I mean, I've seen this construct many times, and the question deserves a place in the Perl FAQ. Please refer back to: http://

RE: max/min

2002-04-11 Thread Bryan R Harris
lto:[EMAIL PROTECTED]] > Sent: Thursday, April 11, 2002 5:52 PM > To: [EMAIL PROTECTED] > Subject: Re: max/min > > > > i like: > $max=0; > map {$max=$_ if($_>$max)} @listofvalues; > -

Re: max/min

2002-04-11 Thread Bryan R Harris
After I sent this I had a flash of enlightenment: $max = (sort {$a <=> $b} @_)[-1]; May be slower, though, I don't know. - B On Apr 11, Bryan R Harris said: >$someVar = max(@listofvalues); > >Is there a function in perl like this? You could use the List::Util module (from CPAN). Or, yo

Re: max/min

2002-04-11 Thread bob ackerman
es) {$max=$_ if($_>$max)} > >> -Original Message- >> From: bob ackerman [mailto:[EMAIL PROTECTED]] >> Sent: Thursday, April 11, 2002 5:52 PM >> To: [EMAIL PROTECTED] >> Subject: Re: max/min >> >&

RE: max/min

2002-04-11 Thread Nikola Janceski
ACK! void use of map! change it! change it! $max=0; foreach (@listofvalues) {$max=$_ if($_>$max)} > -Original Message- > From: bob ackerman [mailto:[EMAIL PROTECTED]] > Sent: Thursday, April 11, 2002 5:52 PM > To: [EMAIL PROTECTED] > Subject: Re: max/min > >

Re: max/min

2002-04-11 Thread bob ackerman
On Thursday, April 11, 2002, at 01:42 PM, Jeff 'japhy' Pinyan wrote: > On Apr 11, Bryan R Harris said: > >> $someVar = max(@listofvalues); >> >> Is there a function in perl like this? > > You could use the List::Util module (from CPAN). Or, you could write your > own: > > sub max { > my

Re: max/min

2002-04-11 Thread Jeff 'japhy' Pinyan
On Apr 11, Bryan R Harris said: >$someVar = max(@listofvalues); > >Is there a function in perl like this? You could use the List::Util module (from CPAN). Or, you could write your own: sub max { my $max = shift; for (@_) { $max = $_ if $_ > $max } return $max; } -- Jeff "japh