develooper Front page | perl.perl5.porters | Postings from July 2010

Re: Order of evaluation of terms (was peephole optimiser could prune more dead code)

Thread Previous | Thread Next
From:
David Golden
Date:
July 15, 2010 11:47
Subject:
Re: Order of evaluation of terms (was peephole optimiser could prune more dead code)
Message ID:
AANLkTim7Pkd4adys0-o7JnyYHcBRT_h4t_VAmb_Sojwu@mail.gmail.com
On Thu, Jul 15, 2010 at 2:31 PM, Jan Dubois <jand@activestate.com> wrote:
> $ perl -E 'sub AUTOLOAD { say $AUTOLOAD; ++$i } say a() + b() * c()'
> main::a
> main::b
> main::c
> 7
>
> So it does call a() first, even though the multiplication of b() and c()
> happens before the result is added to a(). But there is nothing in the
> operator precedence description that would forbid Perl from delaying
> evaluation of a() until after b() * c() has been computed.

C<< a() >> is a term.  Perlop says "A TERM has the highest precedence
in Perl."  Doesn't that meant that all terms get evaluated first, then
all lower precedence operations happen.  And because terms are left
associative, they should be evaluated left to right.

-- David

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