>
> >   BRH> My question is:  why?  Seems like such an easy thing to have done.
>

The answer is simple, the docs say so. The docs state the following in
"perldoc perlsyn" under section "Foreach Loops":

     If the variable is preceded with the keyword "my",
     then it is lexically scoped, and is therefore visible only
     within the loop.  Otherwise, the variable is implicitly
     local to the loop and regains its former value upon exiting
     the loop.  If the variable was previously declared with
     "my", it uses that variable instead of the global one, but
     it's still localized to the loop.  This implicit
     localisation occurs only in a "foreach" loop.

The last line states this ONLY happens for a foreach loop. If you want
localization for while loops you must be explicit with

local $_;
while(<FILE>){
 ## blah
}

Obviously you assumed that it worked that way for while loops and
maybe even do{} while or do{} until loops. It even states near the end
of that section:

     "foreach" probably won't do what you expect if VAR is a tied
     or other special variable.   Don't do that either.

I agree with Uri, you need to make it readable or else you will have
problems later.


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to