in reply to Re: flip flop operator and if statement
in thread flip flop operator and if statement

Hi Athanasius,

Thanks for quick response. What about if the if statement is like

. if(($p=3)..5)

. if (($c=1 and $p=3)..5)

  • Comment on Re^2: flip flop operator and if statement

Replies are listed 'Best First'.
Re^3: flip flop operator and if statement
by Athanasius (Archbishop) on Sep 20, 2014 at 06:54 UTC

    Hello again iThunder,

    if(($p=3)..5)

    This assigns 3 (which is non-zero and therefore true) to $p on each loop iteration. So the left-hand side of the flip-flop operator never becomes false, and the if block is always executed.

    if (($c=1 and $p=3)..5)

    Again, on each loop iteration this assigns 1 to $c and 3 to $p, then ands them together. And since true and true always evaluates to true, the if block is always executed.

    This is beginning to look like an XY Problem. What are you really trying to do with the flip-flop operator?

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

      but then what should be the value of $p.

      " Perl, as a convenience, returns “true” in the form of a sequence number."

      shouldnt the value of p in every iteration increment by one?

        Yes, if $p were being assigned the return value of the flip-flop operator, as in the OP, then it would indeed be incremented by one on each iteration in which the flip-flop operator evaluates to true. But by using parentheses in:

        if(($p=3)..5)

        you ensure that 3 is assigned to $p before the flip-flop operator is evaluated. Then the value of $p (now 3) is used in the evaluation of the flip-flop operator; and since 3 is “true” in Perl, the operator returns a sequence number (which is also true). That sequence number is not assigned to any variable, it’s just used to determine the outcome of the if statement.

        Hope that helps,

        Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

        > shouldnt the value of p in every iteration increment by one?

        In your OP you already showed that it does.

        Cheers Rolf

        (addicted to the Perl Programming Language and ☆☆☆☆ :)

Re^3: flip flop operator and if statement
by Anonymous Monk on Sep 20, 2014 at 06:26 UTC

    What about them?

    Avoid it also?