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

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

Thread Previous | Thread Next
From:
Abigail
Date:
June 26, 2018 17:21
Subject:
Re: [perl #133301] Evalulation order during concat changed
Message ID:
20180626172742.GC1345@almanda.fritz.box
On Tue, Jun 26, 2018 at 01:54:27AM +0200, Tomasz Konojacki wrote:
> On Mon, 25 Jun 2018 04:46:07 -0700
> " \(via RT\)" <perlbug-followup@perl.org> wrote:
> 
> > I presume this is down to the new multiconcat op, but the following
> > line has changed behaviour and I couldn't see any mention of it in
> > the docs.
> > 
> > cat poc.pl; perl poc.pl; perl2 poc.pl
> > $n=1;print$^V.' '.$n.' '.--$n."\n";
> > v5.26.1 1 0
> > v5.28.0 0 0
> > 
> 
> I'm not 100% sure if it's relevant, but perlop says:
> 
> Note that just as in C, Perl doesn't define when the variable is incremented or decremented. You just know it will be done sometime before or after the value is returned. This also means that modifying a variable twice in the same statement will lead to undefined behavior. 


I'd argue that the 5.28.0 version is more correct than the 5.26.1 one.
While it's undefined what the value of '$n' should be, '--$n' should
be 0, not 1. After all, it should return 1 less than the original value
of $n, which starts out as 1.

Note also that I cannot reproduce this. Running this with various versions
of Perl, I get:

    #!/opt/perl/bin/perl

    use 5.010;

    use strict;
    use warnings;
    no  warnings 'syntax';

    my $n = 1;
    say $^V, " ", $n, " ", -- $n;

    __END__
    v5.18.4 0 0
    v5.20.3 0 0
    v5.22.4 0 0
    v5.24.0 0 0
    v5.26.2 0 0
    v5.28.0 0 0




Abigail

Thread Previous | 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