note
ikegami
<blockquote><p><i>clearly, there are two different mechanisms: the first does not do aliasing, whereas the second does. </i></blockquote>
<p>How can you claim that <c>for(1..3)</c> doesn't alias when you can clearly [id://946672|see] <c>++$_;</c> having an effect on what it returns?
<p>In both <c>for(1..3)</c> and <c>for(1)</c>, <c>$_</c> is aliased to each value returned by the expression in the parens.
<blockquote><p><i>I'm sorry, but you're dead wrong here: </i></blockquote>
<p>First, your example does not demonstrate a lack of aliasing. It just shows that <c>$_</c> isn't aliased to <c>$a</c>. That's to be expected, because <c>1..$a</c> doesn't return <c>$a</c> anymore than <c>0+$a</c> does.
<p>Second, you pulled a switcheroo. I said <c>for(1..3)</c> aliases (and [id://946672|proved] that it does), but your code uses <c>for(1..$a)</c>. <c>for(1..$a)</c> is implemented differently; it's a counting loop and not a foreach loop. It still aliases, though.
<blockquote><p><i>Is there any proof of that intention? Best in perldoc?</i></blockquote>
<p>There was code written to specifically perform this effect. By definition, the effect must be intentional.
946488
946908