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

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

Thread Next
From:
=?us-ascii?Q?Wolf-Dietrich_Moeller_=28Munchen=29?=
Date:
August 10, 2018 16:25
Subject:
RE: [perl #133301] Evalulation order during concat changed
Message ID:
5057_1533918321_5B6DBC6D_5057_5_1_000001d430c6$ad9359c0$08ba0d40$@de
Hi,
I think James got the correct point, that the new OP_MULTICONCAT
changes the order of execution.
Unfortunately he used a in-/decrement to change his variable $n,
so I agree with the comments of others with regard to the
order of storing of in-/decremeted variables.
But this has hidden the real issue.

Please see the following:

#### test program ####
$e = 'ab'; $f = 'cd'; $x = $e.$f.($f = 'FF');print '$x = '.$x;
#### end test program ####

#### output test program ####
$x = abcdFF     #### up to Perl 5.26
$x = abFFFF     #### in Perl 5.28.0
#### end output ####

As 'concat' operation is left-associative (see perlop-documentation),
first $e.$f is evaluated. As second step the following bracket
is evaluated, assigning 'FF' to $f. As third step the second
concat is evaluated.

Now in Perl 5.28 with the MULTI_CONCAT this execution model
is no longer valid. Now all inputs to the multiconcat are collected
before the execution of any concatenation, as if the series of concat
operations would be one list operator expecting a list
(but still giving scalar context to the elements in the list).
This means that all concatenations are executed after evaluation of
all arguments (as it is correct for functions in list context).

For me the test program above does not violate any requirements
in the perl documentation, and the result abcdFF should be the
correct result (as up to Perl 5.26).
Thus for me this is an incompatible change to a
series of single concat '.' operations.

Wolf

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About