in reply to Short circuits in Logical AND (&&)
There's a logic error. You want to idle until both A and B are true. But the way you have it constructed, if A is true, then it will stop executing. Or if B is true, it will stop. The only way it can keep going is if both are not true.
It's difficult to spot because you're testing for the Boolean truth of a negative. What you're saying is "While A is untrue and B is untrue they both are untrue, so keep looping." But that overlooks if A is true and B is not. If A is true, then it realizes the first term is equal to true which gives you a boolean false in the first term, which collapses your 'and'. If either one of the terms evaluates to Boolean false, the 'and' cannot be true, so the while loop terminates.
You probably want:
while( $worker1Finished ne 'true' or $worker2Finished ne 'true' ) { #... }
In other words: "While A is untrue or B is untrue then both A and B cannot be true, so keep looping."
In that case, as long as either one of them is not 'true', you continue. The only way to stop is if both of them are not true. It could be much easier to wrap your mind around the logic (at least it is for me) if you simplify it a little by using an until() block. I rarely use them in the until(){} form, but this seems like an ideal situation; especially since you said right at the top of your post "I want to do something until..." (paraphrasing):
until( $worker1Finished eq 'true' and $worker2Finished eq 'true' ) { print "."; sleep 1; }
Read that as "Until A is true and B is true, keep looping."
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Short circuits in Logical AND (&&)
by vishi (Beadle) on Aug 02, 2011 at 06:36 UTC | |
by davido (Cardinal) on Aug 02, 2011 at 06:51 UTC | |
by vishi (Beadle) on Aug 02, 2011 at 08:59 UTC |