in reply to post-increment/pre-increment blues

Hi,

first off, i can't explain my answers for everything including and after the 3rd print statement. My guess was:

my $i = 0; print ++$i + 1," I: $i\n"; # guess 2 print $i++ + 1," I: $i\n"; # guess 2 print $i + $i++," I: $i\n"; # guess 4 print ++$i + ++$i," I: $i\n"; # guess 9 print ++$i + $i++ + 1," I: $i\n"; # guess 12
(attached the I: printout) Obviously wrong, as perl spills 2,2,5,10,14 out. Tried to dig a little bit deeper into it, but had not much luck. The 3rd print statement somewhat mystifies me, as I think $i should have a value of 2 there. If I replace the first $i with 2, then the guess of 4 is correct. However the printout shows still 3. Could someone explain the evaluation order to me?

Bye
 PetaMem