I know the subroutine in perl pass arg by reference. But in the below code, the foreach loop in the subroutine should not be changing the value for @list because the my $i should be creating a new lexically scope var $i. Any assignment to $i should be lexically scope but not changing the @list value.
Can anyone explain what is happening inside the foreach loop that causes the value change to @list?
sub absList {
foreach my $i (@_) {
$i = abs($i);
}
}
@list = (-2,2,4,-4);
absList(@list);
print "@list";
Outputs:
2 2 4 4