in reply to Re: getting the highest value in a simpler way
in thread getting the highest value in a simpler way

I realize this is a very old thread, but I just found it and was wondering about the efficiency of this. I understand you could have a long, complicated expression with no room for if statements, with [ $x => $y ] -> [ $x <= $y ] as just a small portion of that expression and the example of my $highestvalue is just a simple example. However if you were in a loop, and just wanted to keep overwriting $highestvalue every time you find a higher value, wouldn't it be better to write it this way?:
my $x = 0; foreach $y (@lots_of_values){ $x = $y if $y > $x; } return $x;
Is that just as efficient as writing it this way?:
my $x = 0; foreach $y (@lots_of_values){ $x = [ $x => $y ] -> [ $x <= $y ]; } return $x;
The second way seems overly complicated in this case.

Replies are listed 'Best First'.
Re^3: getting the highest value in a simpler way
by BrowserUk (Patriarch) on Mar 17, 2011 at 21:18 UTC
    Is that just as efficient as writing it this way?:

    Actually, yours is close to 10x more efficient. There is no merit to the 'cute' method beyond it cuteness.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      It makes for a damn good interview question. Asking someone to explain it tells you a lot about how deeply they understand several concepts in Perl. So there's another use :D