On Thu, Aug 09, 2001 at 01:36:28PM -0700, Andrew Ho wrote:
> Hello,
>
> r>I have the following situation... it is not big issue but
> r>i'm interested why this happen...
> r>
> r> my $ID = 555;
> r> sub blah {
> r> ...
> r> $ID = selectrow query;
> r> ...
> r> }
>
> This is, in fact, a big issue. You should see a message in your error log
> "shared variable $ID will not stay shared." You should not use a my
> variable defined at the top level of your Apache::Registry script in a
> subroutine. See this entry in the mod_perl guide:
>
> http://perl.apache.org/guide/perl.html#my_Scoped_Variable_in_Nested_S
>
> The workaround is to make $ID a package global (use vars qw($ID)).
With Perl 5.6, the following are roughly equivalent:
use vars qw($ID);
our $ID;
However, you will need to put the `our' declaration within the block (which
may happen implicitely with Apache::Registry).
So (pre-5.6):
use vars qw($ID);
sub foo {
$ID = shift;
}
But (>= 5.6):
sub foo {
our $ID = shift;
}
--James