$_ will hold the reference, not the copy of variable

#!/usr/bin/perl
@list=qw(one two three);
foreach(reverse @list) {
print “$_n”;
$_=”foo”;
}
print “$list[0]n”;

Finally it will pring ‘foo’ not ‘one’. Because
$_ isn’t a copy of the list element, it’s a reference. Modifying it will change the list.

Leave a Reply

Your email address will not be published. Required fields are marked *