--- "Robin Lavallee (LMC)" <[EMAIL PROTECTED]> wrote:
> Then can someone explains why the following code:
> 
> #---Begin Code---
> use strict;
> my $par="50";
> print "$par\n";
> 
> my @arr = ('first', 'second', 'third');
> foreach $par (@arr)
> {
>       print "$par\n";
> }
> print "$par\n";
> #---End Code-----
> 
> produces the following output:
> 50
> first
> second
> third
> 50

Looked it up. Check perldoc perlsyn under foreach loops:

<quoting>
The foreach loop iterates over a normal list value and sets the
variable VAR to be each element of the list in turn. 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. 
</quoting>


__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/

Reply via email to