On Fri, Jun 3, 2011 at 1:23 PM, Jim Gibson <jimsgib...@gmail.com> wrote:
> Declare the variable just before the loop, and remove the 'my' from the > foreach statement: > > my $name; > foreach $name ( ... ) { > ... > } > That won't do. What that code actually translated to is my $name; for my $name ( ... ) { ... } With the second $name masking the first! IIRC this is explained somewhere in PBP, but I don't have the book at hand right now. In any case, if you want to use the variable outside of the for, don't name the two variables the same. The rough rule of thumb is that leaving off the my in a for(each) is probably introducing subtle bugs into your program. Brian.