At 16:39 2001.06.19, Jeff 'japhy' Pinyan wrote:
>On Jun 19, Bob Mangold said:
>
>>I may have a bug somewhere in my code, but I can't find it. Before I
>>look again though please answer this for me.
>
>>my ($line) = "hello";
>>foreach $line (<>){
>>     ..... whatever
>>}
>>print $line;
>>
>>Should it print the last line in <> or 'hello'? 
>
>I don't think the other responders tested their code.  If they had, they'd
>see that $line would retain its value.
>
>  my $line = 1;
>  for $line (1 .. 10) { ; }
>  print $line;  # 1
>
>This is because the looping variable is implicitly localized to the loop
>itself.  This is not a bug.

Has this always been the case? I was under the impression that the syntax 

        for my $line (1 .. 10) { ; }

was introduced to allow an easy way to localize the iteration variable. It doesn't 
make mush sense if the itaration variable is localized by default.

Just wandering.


-----------------------------------------------------------
Éric Beaudoin                <mailto:[EMAIL PROTECTED]>

Reply via email to