Yes, there are a lot of ways to write it correctly, and a lot of incorrect ways too. ;) The one you proposed should work fine. But I would use the lower precedence operators:

while( not ( $worker1Finished eq 'true' and $worker2Finished eq 'true' ) ) { # ... }

...to at least eliminate one set of parens. In fact, if my memory of the precedence tables serves me (which it may not), you could eliminate the other set of parens like this:

while( not $worker1Finished eq 'true' && $worker2Finished eq 'true' ) { # ... }

Because 'eq' is higher precedence than &&, and && is higher precedence than 'not', so eq binds first, && second, and 'not' last.

But the gods gave us 'until(){}' because it suited them to do so. While it's important to use caution when wielding negatives (and double negatives, etc.), it is useful sometimes. My preference in this case is to use it.

until( $worker1Finished eq 'true' and $worker2Finished eq 'true' ) { # ... }

Personal preference. But to me "until this and that keep looping" reads better than "while not both this and that keep looping."


Dave


In reply to Re^3: 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.