Hi
On 26 Jun 2013 09:49, "lee" <l...@yun.yagibdah.de> wrote:
>
> Hi,
>
> the following example doesn't compile:
>
>
> use strict;
> use warnings;
>
>
> sub test {
>     print $counter . "\n";
The variable $counter is not known here
> }
>
>
> 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?
You trying to print a variable $counter that was initialized outsider the
scope of the subroutine.
>
>
> --
> "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
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>

Reply via email to