Hi Lee, On Wed, 26 Jun 2013 10:18:44 +0200 lee <l...@yun.yagibdah.de> wrote:
> Hi, > > the following example doesn't compile: > > > use strict; > use warnings; > > > sub test { > print $counter . "\n"; > } > > > my $counter = 0; > while($counter < 5) { > test(); > $counter++; > } > > > It says "Global symbol "$counter" requires explicit package name ...". > When I put the subroutine after the 'while' loop, it works just fine, so > what's the problem? The subroutine does not see the lexical $counter variable because it was declared after its scope. For more information, see: * http://www.plover.com/FAQs/Namespaces.html Regards, Shlomi Fish -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ Stop Using MSIE - http://www.shlomifish.org/no-ie/ John: Hey, we are completely non-violent vampires. We don’t suck blood. Selina: I thought all vampires suck blood. John: Bullocks, hen. Vampires come in all shapes and sizes. — http://www.shlomifish.org/humour/Selina-Mandrake/ Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/