#!/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.
When curiosity outbursts …!!!
#!/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.