#!/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.
#!/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.
Tags:
0 responses so far ↓
There are no comments yet...Kick things off by filling out the form below.
Leave a Comment