I used to always get bitten by this one:
use strict;
my $name;
foreach $name (qw/alfred benjamin casey donald eugene/)
{
print "$name\n";
}
print "*$name*\n";
Of course this is simplified, but doesn't it seem like $name should be equal to "eugene" after the loop? But it isn't. It's undefined, because it was undefined at the start of the loop. So if you want to do something with the elements of the array and end up storing the last one as a side effect you have to do it in a similar way to this:
use strict;
my $name;
foreach my $loopname (qw/alfred benjamin casey donald eugene/)
{
$name = $loopname;
print "$name\n";
}
print "*$name*\n";
Which has never seemed as DWIMish as I wished for.
;)
jarich