perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brian Gaber" <Brian.Ga...@PWGSC.GC.CA>
Subject RE: param and mod_perl
Date Fri, 13 Jun 2008 19:34:30 GMT
I just did as you suggested.

Now in the log I get a

Variable "$q" will not stay shared at ...

error from the $q->param('deptLtr') in the subroutine.

When I read the mod_perl docs they suggest that use vars was one
approach to fix the "Variable X will not stay shared at" error.

What is the recommended approach?  Pass a reference to $q?


-----Original Message-----
From: Michael Peters [] 
Sent: Friday, June 13, 2008 3:21 PM
To: Brian Gaber
Subject: Re: param and mod_perl

Brian Gaber wrote:
> Using $q was not successful. 

That's because you ignored my advice :)

> Here is what I have done:
> use vars qw($q);

That makes $q a global. Bad, bad, very bad. Slap yourself on the wrist.
Remove that "use vars" line.

> $q = CGI->new();

Now replace that with

  my $q = CGI->new();

> sub print_form {
>    my $dept2show = 'A';
>    if ( $q->param('deptLtr') ) {
>       ($dept2show) = $q->param('deptLtr') =~ /^([a-zA-Z]{1})$/;
>    }
> 	I am running this script simultaneously on two PCs.  Sometimes 
> $dept2show has the expected value, but often is has the an old value.

This is because Apache is using multiple processes to handle things.
Sometimes you're hitting a process for the first time, so it creates an
new CGI object and all is well. But sometimes your request goes back to
a process that has already loaded and executed this code before, so $q
is not a new CGI object.

Michael Peters
Plus Three, LP

View raw message