[EMAIL PROTECTED] wrote:
Hi, With regards to the script below, can somebody explain to me why $testcounter after counting 1,2,3, remains at 3 all the time. I thought it would have been reset to zero by the outer while loop.

In addition to the explanation and sample solution that Rob posted, making the sub anonymous also works.

        test() if (1);
sub test {
          print "$testcounter.\n\n";
        }

    my $test = sub {
        print "$testcounter.\n\n";
    };
    $test->();

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to