in reply to Why doesn't the angle operator localize $_
I think maybe a better question would be, "why does for (LIST) {} localize $_". The answer would be that $_ (and in fact whatever iterator var is used) is aliased to value in the list. This allows all kind of funkyness, but also effectively means that the var used is localized (otherwise it couldnt be an alias temporarily.)
Contrast this to a three argument for loop (which is really a while loop in disguise, or perhaps its the other way around ;-), which doesnt alias, and doesnt localize.
Going back to the IO operator, how could we alias it? The data comes from a file. Theres nothing to alias to. A change to the var that we read in won't change the file. Wheras a change to the var in a for loop does change the thing we are iterating over. Both of these behaviours are sensible and useful, but you have to ask the right question.
E:\>perl -le "$x=10; @a=(0..5); for $x (@a) { print $x; $x=int(rand 10 +0); } print $x; print qq(@a)" 0 1 2 3 4 5 10 41 44 77 55 23 70
BTW, of course Abigail-II is right that by now theres no way to tell, (at least not without lots of research, and even still it might come down to an on the spot decision by Larrry that he may or may not remember), but i would guess that aliasing is part of it.
First they ignore you, then they laugh at you, then they fight you, then you win.
-- Gandhi
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Why doesn't the angle operator localize $_
by welchavw (Pilgrim) on Oct 16, 2003 at 15:12 UTC |