B. Fongo wrote:
> Hello,
> 
> I'm working on my first Perl project. Most of my cgi programs work ok,
> but a look at the apache error log reveals this warning which is
> clear to me: 
> 
> Variable "$xy" will not stay shared at
> /data/www/cgi-perl/envir.pl line
> 19. [Wed Jul 16 11:44:57 2003] [error] Undefined subroutine
> &Apache::ROOT::cgi_2dperl::environ_2epl::start_html called at
> /data/www/cgi- perl/envir.pl line 20.
> 
> For instance: This code will trigger such warning.
> 
> #!/usr/bin/perl -w
> use strict;
> use CGI;
> my $xy = new CGI;
> print $xy->header();
> print $xy->start_html();
> print $xy->p(" Perl-CGI");
> print $xy->end_html;
> 
> #########################
> 
> I tried several alternatives, like invoking print() only once at
> header. But I can't feature out what that warning actually means. My
> apache is configure with mod_perl. 

The problem is caused by the way Apache::Registry handles your script. 
For the gory details see:
<http://perl.apache.org/docs/general/perl_reference/perl_reference.html#my__
_Scoped_Variable_in_Nested_Subroutines>

The solution I always use is to change all file-scoped lexicals to globals
and protect them with "local" so you get fresh copies with each request.

Instead of:

   my $xy = new CGI;

Do:

   our $xy;
   local $xy = new CGI;

> 
> Besides that, my project will consist of 1 main Perl script and
> several modules in a subdirectory which will be performing various
> functions. Now; what I intend to do is always send the main script a
> parameter through the URL, which will then indicate which of the
> modules should be called.  Each of my modules will contains
> subroutines for various functions: My question is: How do I send a
> parameter to my script through a link on my web page? I tried
> something like this, but did not work. 

What did it do?

> 
> <a href="cgi-perl/mainprogram.pl?action=cup_of_coffee">A cup of
> coffee </a> 

That looks OK, except that the URL is relative, so you need to make
sure you know where you are.

> 
>   What I'm trying to do here is to send the string "cup_of_coffee" to
> the main program. 
> 
> The main program will have something like this to store the parameter
> from the url: @forwarded_by_url = ??? # Am not sure here.

Assuming $xy is the CGI object:

   $action = $xy->param('action');   # sets $action to 'cup_of_coffee'

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to