in reply to Re: Re: Multi-Threaded Elevator Simulator
in thread Multi-Threaded Elevator Simulator

man...I hate when people point out the obvious when its not even related to the point. The point was to test the new and improved 5.8 threading...which I think was a good idea....besides...
$max_wait = $wait1 > $wait2 ? $wait1 : $wait2;

does not equal
$max_wait = $wait1 if $wait1 > $max_wait;

because $max_wait is an aggregate value and is not in the same scope....you would lose your max value at every iteration....instead...
$max_wait = ($wait1 > $wait2) ? ($wait1 > $max_wait) ? $wait1 : $max +_wait : ($wait2 > $max_wait) ? $wait2 : $max_wait;

would work....
-insomnia

Replies are listed 'Best First'.
•Re: Re: Re: Re: Multi-Threaded Elevator Simulator
by merlyn (Sage) on Aug 07, 2002 at 22:56 UTC
    $max_wait = ($wait1 > $wait2) ? ($wait1 > $max_wait) ? $wait1 : $max +_wait : ($wait2 > $max_wait) ? $wait2 : $max_wait;
    If I was your teacher, I'd rap you on the knuckles with a ruler for writing that! Gah!

    Please, consider this much clearer alternative:

    $max_wait < $_ and $max_wait = $_ for $wait1, $wait2;
    Or, if you don't like the "and" there...
    for ($wait1, $wait2) { $max_wait = $_ if $max_wait < $_; }

    -- Randal L. Schwartz, Perl hacker

      Personally, I've always been fond of (sort {$a<=>$b} ($wait1, $wait2))[-1]...

      =cut
      --Brent Dax
      There is no sig.