in reply to Re^2: Evaluation Order again.
in thread Evaluation Order again.

Your incorrect expectation has nothing to do with operand evaluation order; it's that you didn't take into account that Perl always passes by reference.

The following demonstrates that the operand evaluation order used is the one that was documented.

use Data::Alias qw( alias ); sub func { print $_, ' ' for @_; print "\n"; $_[2]; } { my $i = 3; func( $i, ++$i, $i+2 ); } { my $i = 3; local @_; alias push @_, $i; alias push @_, ++$i; alias push @_, $i+2; &func; }
4 4 6 4 4 6

Replies are listed 'Best First'.
Re^4: Evaluation Order again.
by Tanktalus (Canon) on May 30, 2016 at 19:35 UTC

    Ah, of course. That distinction becomes important so rarely for me that it's easy to forget. So, to remove the referencing, and make it show up "as expected", I just add zero to each item, and I get what I expect:

    use strict; use warnings; sub func { print $_, ' ' for @_; print "\n"; $_[2]; } my $i = 3; my $rv = func(0+$i, 0+ ++$i, 0+$i+2);
    And now I get my "3 4 6" - and everything makes sense again. See? I knew I did something wrong ;)