perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Peters <mpet...@plusthree.com>
Subject Re: CGI.pm param and mod_perl
Date Fri, 13 Jun 2008 19:20:59 GMT
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


Mime
View raw message