Front page | perl.perl5.porters | Postings from August 2018

## Re: [perl #133301] Evalulation order during concat changed

From:
Eirik Berg Hanssen
Date:
August 10, 2018 21:20
Subject:
Re: [perl #133301] Evalulation order during concat changed
Message ID:
24968_1533936047_5B6E01AF_24968_15_1_CAHAeAG5LMX_YGYvmtXbuOCtmOrBgc005qYreAC+K_n0YHN9H8w@mail.gmail.com
```On Fri, Aug 10, 2018 at 10:08 PM David Nicol <davidnicol@gmail.com> wrote:

> I don't think it's possible to interpret perldoc perlop's
>
> *Operator precedence* means some operators are evaluated before others.
> For example, in 2 + 4 * 5 , the multiplication has higher precedence so 4
>  * 5 is evaluated first yielding 2 + 20 == 22 and not 6 * 5 == 30 .
>
> *Operator associativity* defines what happens if a sequence of the same
> operators is used one after another: whether the evaluator will evaluate
> the left operations first, or the right first. For example, in 8 - 4 - 2 ,
> subtraction is left associative so Perl evaluates the expression left to
> right. 8 - 4 is evaluated first making the expression 4 - 2 == 2and not 8
>  - 2 == 6 .
>
> in a way that allows the right side of a left-associative operation to be
> evaluated first and still conform with the documentation.
>

Oh, yes it is: The docs for associativity here speak of the order in
which the ("same-operator") _operations_ will be evaluated – not the order
in which their _operands_ will be evaluated.

In C<< \$e.\$f.(\$f = 'FF') >>, the left-most concatenation is, per the
associativity docs, evaluated before the right-most concatenation.  But the
evaluation order of the _operands_ of the right-most concatenation – that
is, whether or not the left-most concatenation is evaluated before the
assignment – is not specified in the quoted part of the docs.  And that is
the change in question; it may be fair to criticise it, but I don't think
it is fair to suggest it doesn't conform with this documentation.

If I recall correctly (and it hasn't changed since last this topic was
raised), the assignment, short-cutting (logical), and comma are the only
operators that specify an (operand) evaluation order.  Every other operator
leaves the (operand) evaluation order unspecified.

Eirik

```