in reply to Re: Should we Localize $_ ?
in thread Should we Localize $_ ?

This gives you no protection. Witness:
my @foo = (2, 4, 8); foreach my $num (@foo) { $num *= 2; } $, = ",";print @foo;print "\n";

Like Ovid says below, this is a 'problem' of aliasing. But it actually isn't a problem unless you assign to $_ (or $num, or whatever your iterator is called), which is typically a deliberate decision, and not usually something that happens by accident. Although I can imagine typos (the olde =/== switcheroo), or some weird precedence error doing this assignment. Also, if your &dosomething operates on its @_ directly, you'll be at risk; i.e., this does the same thing as the above:

my @foo = (2, 4, 8); foreach my $num (@foo) { &double($num); } $, = ",";print @foo;print "\n"; sub double { $_[0] = 2*$_[0]; return $_[0]; }
A safe version of &double would be:
sub double { my $num = $_[0]; $num = 2*$num; return $num; }
I suspect that this is probably the most likely way the aliasing feature can botch your expected results, but you're all clear so long as all your subs never access their own @_ except to assign it to lexical variables.

-- Frag.