No such thing as a small change | |
PerlMonks |
comment on |
( [id://3333]=superdoc: 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 reply to Re: Why is the execution order of subexpressions undefined?
by ikegami
|
|