Angel Flower,

'my' means that it is local to the main program, so your subroutine
won't see that version of "$counter". Your subroutine will create and
access a global version of "$counter" which is separate and doesn't get
re-initialised.

You need to read up on 'my' and references - do "man perlref" an
"perldoc -f my".

John


angel flower wrote:

> hi,
>
> I am new to mod_perl.This is my first doubt,and I need some help.
>
> I test this script under mod_perl:
>
>
>
> #!/usr/bin/perl -w
> use strict;
> use warnings;
>
> print "Content-type: text/plain\r\n\r\n";
>
> my $counter = 0; # Explicit initialization technically redundant
>
> for (1..5) {
> increment_counter();
> }
>
> sub increment_counter{
> $counter++;
> print "Counter is equal to $counter !\r\n";
> }
>
>
> When I reload from user agent,this script can't work correctly.It
> seems that the script cached the result in memory.The output is:


Reply via email to