On Thursday, November 14, 2002, at 07:17 AM, Brian Ingerson wrote:
$_ is a global variable just like any other. If you clobber it, you may clobber someone else's data.On 13/11/02 16:08 +0100, [EMAIL PROTECTED] wrote:Wow. That's crazy. How could $_ affect anything? Would you mind sending aA problem we had with dynamic loading of Inline modules has been tracked down to the use of $_ in Inline::denter. With the attached patch it works OK
brief expanation? I'll apply the patch.
The reason $_ is usually safe is that you don't generally assign things to it, you let perl do the assigning implicitly (by using a foreach(), map(), grep(), etc.) and in this case it localizes the variable before assignment.
But if you assign explicitly and you don't localize, clobber city.
The following script demonstrates:
#!/usr/bin/perl
top();
sub top {
local $_ = 5;
inner();
print "\$_ is $_\n";
}
sub inner {
$_ = 7;
}
__END__
*************** *** 188,193 **** --- 189,195 ---- $o->{done}++, $o->{level} = -1, return unless @{$o->{lines}}; my ($width, $tabwidth) = @{$o}{qw(width tabwidth)}; while (1) { + local ($_); $_ = $o->{lines}[0];
Incidentally, I'd just write these as
local $_ = $o->{lines}[0]; -Ken