in reply to Using Array Refs
The (explicitly stated or implicite $_) loop variable in foreach loops is always an alias (what Perl calls C-like references) to the element, as opposed to a copy. This has nothing to do with a reference ($a) being involved. If you want to modify the loop variable without modifying the array element, use one of the following workarounds:
foreach (@array) { my $i = $_; # $i is a copy. ... }
or
foreach (@array) { local $_ = $_; # $_ is a copy. ... }
|
|---|