P is for Practical | |
PerlMonks |
Re^4: Playing with non-localized $_ in nested loops.by Aristotle (Chancellor) |
on Aug 23, 2004 at 10:19 UTC ( [id://385040]=note: print w/replies, xml ) | Need Help?? |
There is a difference between localizing $_ and aliasing it to something else. Do not confuse the two. Note also that there is no construct which implicitly localizes $_, but there are several which alias it to something else. Obviously, while(<FH>) cannot alias the variable to anything, because one would have to be able to expect that modifying $_ would actually modify the file. Instead, readline returns a copy of the data found in the file. It really is obvious and very consistent if you think about it. Perl just DWIMs well enough in so many cases that it's easy to overlook some of the ramifications of any single operation. Makeshifts last the longest.
In Section
Seekers of Perl Wisdom
|
|