Maybe easy, maybe not, but:
my $x=5; $x=$x + ++$x + $x++; warn $x; #get 18.
How I undestand that:
1)$x - return's copy of object $x and then return it's value in numeric context.
2)++$x - make increment, but return object $x, this mean that in future if we change it's value also been changed.
3)$x++ - make increment, but return's not icremented copy of object $x.
points 2 and 3 I've check im many examples.
I'm not sure about point 1, because by logic - it must place here original $x, so value must be calculated as 20 (7+7+6)
So this not working code, I know that this is incorrect and can't be submited in production code. It's for my students for good undestanding of this situation.
Will be happy for any answers with proof-links or for answers from greatest monks )
In reply to question 1st - undefined behaviour by rumos2
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |