note
ikegami
<p>It's similar to <c>print($i, $i++, $i);</c>, at least in effect. Perl must place some form of pointer* to <c>$a[$n]</c>'s value on a stack instead of making a new scalar to save speed and memory. The result is that when <c>$a[$n]</c> is changed by the third expression in the list slice, it also changes the value of the second expression.
<p>By explicitly copying the value of <c>$a[$n]</c> into another variable (<c>$x</c>), changes in <c>$a[$n]</c> no longer affect the result of the slice.
<p>* — An alias? A pointer to the SV?
625977
626185