Scope?

On Wednesday, June 26, 2013, lee 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?
>
>
> --
> "Object-oriented programming languages aren't completely convinced that
> you should be allowed to do anything with functions."
> http://www.joelonsoftware.com/items/2006/08/01.html
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org <javascript:;>
> For additional commands, e-mail: beginners-h...@perl.org <javascript:;>
> http://learn.perl.org/
>
>
>

-- 
wapembe
seller of truths, half and whole
inquire about quantity discounts!

Reply via email to