in reply to Short circuits in Logical AND (&&)

If your true and false flags equate to one and zero, you can write your loop like this:

until ($worker1Finished & $worker2Finished) { ... }

Update: s/zero and one/one and zero/

-- Ken

Replies are listed 'Best First'.
Re^2: Short circuits in Logical AND (&&)
by GrandFather (Saint) on Aug 04, 2011 at 02:04 UTC

    however, for the cost of one extra & character (I can supply them very cheaply if you are running out) you can write:

    until ($worker1Finished && $worker2Finished) { ... }

    which will work nicely for all Perl's various true and false values (including not complaining about undef values under strictures).

    True laziness is hard work
Re^2: Short circuits in Logical AND (&&)
by locked_user sundialsvc4 (Abbot) on Aug 02, 2011 at 11:17 UTC

    Uh uh ... is that construction short-circuit?   Not sure that it is.   And if not, “not equivalent.”

    Also, I do not like to write code that “assumes” what “just happens to be the case right now,” in such a way that it requires it and therefore breaks down when something causally unrelated to it (i.e. the assumption...) changes in what ought to be an inconsequential way.   That is the sort of coding that bites you in the punctuation-mark.   I’ve been bitten by it enough times, and have cleaned up after it enough times, to have come to really resent it.

      Uh uh ... is that construction short-circuit? Not sure that it is. And if not, “not equivalent.”
      Rubbish.

      Short-circuiting and not short-circuiting are only non-equivalent if the second expression has side-effects. Since it's not mentioned the variables are tied, it's safe to assume there's not short-circuiting happening.

      So, under the stated assumptions (using 0 and 1), they are equivalent.

      Not that I would use a construct. I find using bit-twiddling operators to do boolean logic a misplaced cuteness that serves nothing. To me, it smells like the author is saying "look at me, I think I've surpassed the level of grasshopper".