From: | Wolf-Dietrich Moeller (Munchen) <wolf-dietrich_moeller [...] t-online.de> |

To: | <perlbug [...] perl.org> |

Subject: | possible inconsistency in "perlop" documentation on associativity of operators |

Date: | Wed, 27 Jan 2016 17:32:17 +0100 |

Hello,

I am not sure if the following issue in the “perlop”-documentation needs clarification.

In the section on “Operator Precedence and Associativity” there is the line:

`“right = += -= *= etc. goto last next redo dump”`

`The “etc.” means to me that all other assignment operators are also right-associative, i.e. in particular also the short-circuit “&&=”, “||=” and “//=”.`

` `

`Taking the explanation in the `**section on “Assignment Operators” (further below in perlop), the example given there for a “combined operator” can be extended to a sequence of operators with “&&=”:**

$y &&= $x += 2; is equivalent to $y = $y && ($x = $x + 2);

Given the short-circuit behavior of ‘&&’, it is clear that the assignment “($x = $x + 2)” in the “equivalent assignment” (right) is not executed if $y == 0 (and correctly the “simple” assignment ‘$y = ’ is right-associative).

`But looking to the “original assignment” (left), where $y only appears to the left of the “&&=” operator, the (effective) associativity for this “&&=” operator is “left”. `

` `

`This is counter-intuitive to the text in the documentation given above, that ALL assignment operators are right-associative.`

`It seems to me that this only applies if a “combined” operator is separated into the equivalent form with “simple” operators; but then it is no longer the “combined” assignment operator.`

Should this be reflected somewhere in the documentation (in the section on “Operator Precedence and Associativity”)?

` `

`This issue is not related to any particular Perl version, as I found the same text already in my old Perl 5.0 Manpages.`

` `

`Best regards`

`Wolf Moeller`