in reply to Re^2: Strange aliasing(?) when modifying variable in range operator
in thread Strange aliasing(?) when modifying variable in range operator

You're welcome! :)

NB: You have no guaranty at all when INSIDE the statement the increment happens, it's only guarantied AFTER the statement.

Most probably is Perl doing internal optimizations here.

Your do-block examples puzzle me, please note the difference between debugger and one-liner

DB<1> $i=1; say for do{$i?$i:($i+1)}..$i++ #6 1 DB<2> q D:\Users\lanx>perl -wE "$i=1; say for do{$i?$i:($i+1)}..$i++ #6" D:\Users\lanx>

again, unpredictable internal optimization.

If interested, you could use B::Concise to track what is happening here...

So Rule Of Thumb:

NEVER mix $i and $i++ (or --$i) inside the same statement.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

  • Comment on Re^3: Strange aliasing(?) when modifying variable in range operator
  • Download Code