Here is how I think about for() assignments:
For a code like,
for ($passed_in)
{
# inside BLOCK
}
Inside the BLOCK,
$_ is equal to
$$ref where
$ref = \$passed_in
Except that if you did change
$_, you will also modify
$passed_in. They are magically tied together,
$_ and the reference, that is.
It is faster this way, since only a REFerence is passed_in. No copy of
$passed_in is made. However, for the following code,
for my $scoped_copy ($passed_in)
{
# inside BLOCK
}
A copy of
$passed_in is made to
$scoped_copy.
The same reasoning above applies to other loop constructs, sub arguments, or CODE BLOCKS of map(), grep(), sort(), etc. for the
$_ @_ $a $b variables.
Again, this is just my observation. Would someone with knowledge of Perl guts confirm that I could continue with this train of thought?