Perlop: ... Auto-increment and Auto-decrement "++" and "--" work as in C. That is, if placed before a variable, they increment or decrement the variable by one before returning the value, and if placed after, increment or decrement after returning the value. $i = 0; $j = 0; print $i++; # prints 0 print ++$j; # prints 1 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. Avoid statements like: $i = $i ++; print ++ $i + $i ++; Perl will not guarantee what the result of the above statements is. ... On 14 Mar 2014, at 17:03, Ralph Grove <grov...@jmu.edu> wrote:
> sub doit { > return ++$g ; > } > > $g = 0; > my $sum = $g + doit() + doit(); > print "$sum \n"; > > $g = 0; > $sum = doit() + $g + doit(); > print "$sum \n"; > > $g = 0; > $sum = doit() + doit() + $g; > print "$sum \n";