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


In reply to Re: Short circuits in Logical AND (&&) by davido
in thread Short circuits in Logical AND (&&) by vishi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.