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

Thank you for answer, Lanx, but range operator is not a "call" (to function), is it? And operators aren't (shouldn't be(?)) executed before arguments are evaluated?

Hm-m, I'm wrong. Back to school...

>perl -wE "$i=1; say $i + ($i+=1)" 4
  • Comment on Re^2: Strange aliasing(?) when modifying variable in range operator
  • Download Code

Replies are listed 'Best First'.
Re^3: Strange aliasing(?) when modifying variable in range operator
by LanX (Saint) on Jun 09, 2018 at 18:19 UTC
    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