Problems? Is your data what you think it is? | |
PerlMonks |
Re: Why is the execution order of subexpressions undefined?by ikegami (Patriarch) |
on Apr 11, 2005 at 23:53 UTC ( [id://446800]=note: print w/replies, xml ) | Need Help?? |
Arguments are evaluated from left to right. (For me. I don't know if this is defined or undefined behaviour.) However, everything is passed by reference (or would that be "passed by alias" in Perl terminology). That explains why ++$i affected the $i. It must be this way to allow $_[0] = 4 to work. The following is the C++ equivalent (ignoring the memory leaks). Try it and you will see similar results.
The following is a good example of the execution order in Perl:
From the above, you can also see the solution to your problem. You can work around the problem by converting lvalues to rvalues:
Of course, you can no longer do $_[0] = 4; from within func if you apply this fix.
In Section
Seekers of Perl Wisdom
|
|