develooper Front page | perl.perl5.porters | Postings from January 2016

[perl #127391] possible inconsistency in "perlop" documentation onassociativity of operators

Thread Next
Wolf-Dietrich Moeller
January 27, 2016 16:32
[perl #127391] possible inconsistency in "perlop" documentation onassociativity of operators
Message ID:
# New Ticket Created by  Wolf-Dietrich Moeller 
# Please include the string:  [perl #127391]
# in the subject line of all future correspondence about this issue. 
# <URL: >

I am not sure if the following issue in the "perlop"-documentation needs

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

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About