in reply to Re^3: Without trying; what do you think this would print? (/left/ side)
in thread Without trying; what do you think this would print?

No, it isn't. No, they need not be.

- tye        

  • Comment on Re^4: Without trying; what do you think this would print? (notabug!)

Replies are listed 'Best First'.
Re^5: Without trying; what do you think this would print? (notabug!)
by wind (Priest) on Apr 30, 2011 at 18:06 UTC

    Well, from my basic understanding of perlop - Assignment Operators those two should be equivalent. Maybe I'm wrong though.

    Fortunately, it's a contrived example anyway.

      Yes. They are both even equivalent to the point of either producing 0 or 1 depending on implementation details including optimizations.

      - tye        

        Tye, don't be silly. I get where you're coming from since you're trying to explain WHY they are different. However, implementations details including optimizations don't matter. Either the language works as documented in perlop or it doesn't and is a bug:

        Assignment operators work as in C. That is,

        $a += 2;

        is equivalent to

        $a = $a + 2;

        although without duplicating any side effects that dereferencing the lvalue might trigger, such as from tie(). Other assignment operators work similarly. The following are recognized:

        **= += *= &= <<= &&= -= /= |= >>= ||= .= %= ^= //= x=

        One of these two things is wrong. Either the documentation or the implementation. My vote is for the implementation.

        Although as I said, it's such a contrived example that I can understand why it wouldn't be a big deal, and that the optimization benefits would be worth the sacrifice.