Perl Monk, Perl Meditation | |
PerlMonks |
Prefix and postfix increment/decrement operator queryby saurabh.hirani (Beadle) |
on Jul 02, 2009 at 12:11 UTC ( [id://776720]=perlquestion: print w/replies, xml ) | Need Help?? |
saurabh.hirani has asked for the wisdom of the Perl Monks concerning the following question: Hi guys, A friend of mine had just asked an interesting question about increment, decrement operators which led to my query. What should be the output of
It should be 21 instead of 20 because if I were to think how the calculation would be done - convert to postfix, push operands on stack till operator is encountered, when operator encountered, pop out 2 operands and perform operation and push result onto stack:
A similar explanation can be done for:
Can you guys please tell me how would the postfix calculation progress in case of and
I don't know why the result of ++$a + $a++ turned out to be 23. Thanks for going through,
Back to
Seekers of Perl Wisdom
|
|