John M. Dlugosz has asked for the wisdom of the Perl Monks concerning the following question:
In Seven Uses of local, the unnamed writer at TPJ says that
will blow away the values in @array because of the way foreach aliases $_ with the elements, and that function happens to (implicitly) use $_.foreach (@array) { ... $f = getfile($filename); ... }
So if that's such a problem, why don't we run into it more often? Should we write all our functions to localize $_ just in case someone wants to call it within a foreach loop? Or should the coder of a foreach name his variable or localize it himself if his body is nontrivial?
—John
Back to
Seekers of Perl Wisdom