Perl Monk, Perl Meditation | |
PerlMonks |
Re: Question regarding variable scopeby chimni (Pilgrim) |
on Oct 16, 2003 at 06:49 UTC ( [id://299683]=note: print w/replies, xml ) | Need Help?? |
When you declare my $black_player at the start of the sub .That variable is global through the scope of the sub . (My or our would behave the same with respect to this sub,behaviour would vary with respect to code followinng down the line). When you do a foreach $black_player (@possible_opponents) This effectively overrides the above $black_player .It is local to the loop.Same principle as a pass by value in C. Therefore ,you can rename your looping variable or just do what roger has done ,use $_.
In Section
Seekers of Perl Wisdom
|
|