P is for Practical | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
> there's some logical explanation?
Well ... implementation details and an explicit warning not to mess with side-effects of multiple increments in the same statement.* When calling a sub simple arguments are passed by reference which can be modified (you could call this alias) but the result of increments are passed as values . The increments happen from left to right on the same instance, but will influence the aliases inside the sub.
Does it explain your results?
Cheers Rolf
*) from perlop#Auto-increment-and-Auto-decrement 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:Perl will not guarantee what the result of the above statements is.
updatesorry I just notice that you didn't have multiple increments in the same statement,² but the explanation with call by reference and value still holds:
update²) but already mixing $i and $i++ in the same statement is discouraged! In reply to Re: Strange aliasing(?) when modifying variable in range operator
by LanX
|
|