Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^3: Strange aliasing(?) when modifying variable in range operator

by LanX (Saint)
on Jun 09, 2018 at 18:19 UTC ( [id://1216266]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1216266]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (7)
As of 2024-04-24 09:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found