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
> > > 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
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
> >> 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
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
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
> 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://
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;
>
-
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
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
>>
>&
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
>
>
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
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
$someVar = max(@listofvalues);
Is there a function in perl like this?
- B
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
14 matches
Mail list logo