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

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

Thread Previous | Thread Next
Dave Mitchell
August 11, 2018 15:40
Re: [perl #133301] Evalulation order during concat changed
Message ID:
On Sat, Aug 11, 2018 at 03:36:15PM +0200, Eirik Berg Hanssen wrote:
>   This example demonstrates that the left-hand operand is evaluated _after_
> the right-hand operand, in violation of this "general rule":

There's also an example just with a concat mutator, where the order of
FETCH()es of tied arg changes depending on what the args are. This
ordering is unaffected by the introduction of multiconcat:

    sub TIESCALAR { bless [ $_[1] ]; }
    sub FETCH { my $s = $_[0][0]; print "FETCH($s)\n"; $s }
    sub STORE { print "STORE($_[0][0] => $_[1])\n"; $_[0][0] = $_[1] }

    my ($a,$b,$c);
    tie $a, 'main', 'A';
    tie $b, 'main', 'B';
    tie $c, 'main', 'C';

    $a .= $b;
    #$a .= $b . $c;

with $a .= $b, you get:

    STORE(A => AB)

with $a .= $b . $c you get

    STORE(A => ABC)

Note how it changes from FETCHing the LHS first to the RHS first.

This isn't an example of ordering of operand execution inconsistency,
but of fetching the results of such executions. It none the less
demonstrates the danger of relying on an assumed order.

"You may not work around any technical limitations in the software"
    -- Windows Vista license

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