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

Try the following with and without the 'local $_;' line and you'll see what he's talking about.

use strict; sub getfile { local $_; my $filename = shift; local *F; open F, "< $filename" or die "Couldn't open `$filename': $!"; my $contents; while (<F>) { s/#.*//; # Remove comments next unless /\S/; # Skip blank lines $contents .= $_; # Save current (nonblank) line } return $contents; } my @array = ("base_tester", "Foo.pm"); foreach (@array) { my $filename = $_; my $f = getfile($filename); } print "@array\n";
That's what I tried to see the effects, and I was rather surprised.