|We don't bite newbies here... much|
Question preincrementby himik (Acolyte)
|on Aug 03, 2012 at 13:37 UTC||Need Help??|
himik has asked for the
wisdom of the Perl Monks concerning the following question:
Hello Monks! I have question
How much will this print?
shouldn't it be 4? And not 5?
I test this in PHP and there is 5
1. in the start $a is 1
2. first of all in the print is ++$a and $a become 2
3. second is $a+$a and become 4
4. third is print
5. fourth $a become 3
I found the answer in perldoc
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: