perlfaq nodetype
faq_monk
<P>
Variable suicide is when you (temporarily or permanently) lose the value of a variable. It is caused by scoping through
<CODE>my()</CODE> and
<CODE>local()</CODE> interacting with either closures or aliased
<CODE>foreach()</CODE> interator variables and subroutine arguments. It used to be easy to inadvertently lose a variable's value this way, but now it's much harder. Take this code:
<P>
<PRE> my $f = "foo";
sub T {
while ($i++ < 3) { my $f = $f; $f .= "bar"; print $f, "\n" }
}
T;
print "Finally $f\n";
</PRE>
<P>
The <CODE>$f</CODE> that has ``bar'' added to it three times should be a
new <CODE>$f</CODE>
(<CODE>my $f</CODE> should create a new local variable each time through the loop). It isn't,
however. This is a bug, and will be fixed.
<P>