You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by stevenl <st...@concentric.net> on 2000/08/13 07:25:33 UTC
Problem with form data using mod_perl and CGI.pm
I am running Linux 2.2, Apache 1.3.12, mod_perl 1.24, and CGI.pm 2.70.
If I declare a CGI variable using 'my' (see below) and use mod_perl, I
encounter problems with POST data. On subsequent entries in the form,
it continues to use the old data.
The problem does not appear if I don't use 'my' (and therefore, unable
to 'use strict'), or if I disable mod_perl from my httpd.conf file.
You can test this out with these files. First, run 'httpd -X'. Then
enter some data in the form. On the next submit, the data is not
changed.
Note: The perl script displays the current HTML file plus what you
just entered.
htdocs/form.html
----------------
<html>
<head></head>
<body>
<form actioN="/cgi-bin/form.pl" method="post">
Name:
<input type="text" name="Name" value="">
<input type="submit">
</form>
<!--ARGS-->
</body>
</html>
cgi-bin/form.pl
---------------
#!/usr/local/bin/perl -w
# Problem if declaring $query with 'my' and using
# Apache 1.3.12, mod_perl 1.24, CGI.pm 2.70
use CGI;
my $query = new CGI;
print "Content-Type: text/html\n\n";
open(FD, "../htdocs/form.html") || die $!;
while (<FD>) {
if (/^<!--ARGS-->$/) {
printQueryParams();
}
else { print; }
}
close(FD);
sub printQueryParams
{
my @params = $query->param();
my ($arg, $val);
foreach $arg (@params) {
$val = $query->param($arg);
print "$arg = $val<BR>\n";
}
}
-Steven
RE: Problem with form data using mod_perl and CGI.pm
Posted by Tom Mornini <tm...@infomania.com>.
> > > What is the best way to define a global value like $query if I want to
> > > 'use strict'. I really don't want to be passing $query to all my
> > > subroutines. I could package define it as $main::query but that seems
> > > awkward.
> "perldoc perlref" addresses the nested subroutine problem, and
> suggests using something like this:
>
> local *printQueryParams = sub {
>
> instead of this:
>
> sub printQueryParams {
>
> The assignment to the typeglob is pretty slick in that it let's you
> call the anonymous subroutine as if it were a subroutine named
> printQueryParams.
How about just:
use vars qw ( $query );
to define a package global?
--
-- Tom Mornini
-- InfoMania Printing and Prepress
RE: Problem with form data using mod_perl and CGI.pm
Posted by Bryan McGuire <jo...@mindspring.com>.
"perldoc perlref" addresses the nested subroutine problem, and
suggests using something like this:
local *printQueryParams = sub {
instead of this:
sub printQueryParams {
The assignment to the typeglob is pretty slick in that it let's you
call the anonymous subroutine as if it were a subroutine named
printQueryParams.
-----Original Message-----
From: stevenl@concentric.net [mailto:stevenl@concentric.net]
Sent: Monday, August 14, 2000 3:44 AM
To: Stas Bekman
Cc: Jie Gao; modperl@apache.org
Subject: Re: Problem with form data using mod_perl and CGI.pm
Stas Bekman wrote:
>
> On Mon, 14 Aug 2000, stevenl wrote:
>
> > Thanks. That seems to be the problem, accessing an outer lexical
> > variable in an inner subroutine. I'm not quite sure I understand
why
> > Perl behaves this way. Java seems to handle this just fine with
the
> > expected behavior.
>
> Because Perl != Java. And you are lucky that the last statement
> returns true :) Of course the real explanation would require some
reading
> from you.
>
I thought the whole philosophy behind Perl is that it does what you
expect it to do and this is in no way what anyone would expect it to
behave!
Thanks for the link. I guess I'll read up on this guide more
carefully
before I ask any further questions.
-Steven
> > I'm currently using:
> >
> > use CGI;
> > my $query = new CGI();
> >
> > What is the best way to define a global value like $query if I
want to
> > 'use strict'. I really don't want to be passing $query to all my
> > subroutines. I could package define it as $main::query but that
seems
> > awkward.
>
>
http://perl.apache.org/guide/perl.html#Using_Global_Variables_and_Shar
i
>
> > -Steven
> >
> >
> > Jie Gao wrote:
> > >
> > > On Sat, 12 Aug 2000, stevenl wrote:
> > >
> > > > I am running Linux 2.2, Apache 1.3.12, mod_perl 1.24, and
CGI.pm 2.70.
> > > >
> > > > If I declare a CGI variable using 'my' (see below) and use
mod_perl, I
> > > > encounter problems with POST data. On subsequent entries in
the form,
> > > > it continues to use the old data.
> > > >
> > > > The problem does not appear if I don't use 'my' (and
therefore, unable
> > > > to 'use strict'), or if I disable mod_perl from my httpd.conf
file.
> > > >
> > > > You can test this out with these files. First, run
'httpd -X'. Then
> > > > enter some data in the form. On the next submit, the data is
not
> > > > changed.
> > > >
> > > > Note: The perl script displays the current HTML file plus what
you
> > > > just entered.
> > > > ...
> > >
> > >
http://perl.apache.org/guide/perl.html#my_Scoped_Variable_in_Nested_S
> > >
> > > Jie
> >
>
>
_____________________________________________________________________
> Stas Bekman JAm_pH -- Just Another mod_perl
Hacker
> http://stason.org/ mod_perl Guide
http://perl.apache.org/guide
> mailto:stas@stason.org http://apachetoday.com
http://jazzvalley.com
> http://singlesheaven.com http://perlmonth.com perl.org
apache.org
Re: Problem with form data using mod_perl and CGI.pm
Posted by stevenl <st...@concentric.net>.
Stas Bekman wrote:
>
> On Mon, 14 Aug 2000, stevenl wrote:
>
> > Thanks. That seems to be the problem, accessing an outer lexical
> > variable in an inner subroutine. I'm not quite sure I understand why
> > Perl behaves this way. Java seems to handle this just fine with the
> > expected behavior.
>
> Because Perl != Java. And you are lucky that the last statement
> returns true :) Of course the real explanation would require some reading
> from you.
>
I thought the whole philosophy behind Perl is that it does what you
expect it to do and this is in no way what anyone would expect it to
behave!
Thanks for the link. I guess I'll read up on this guide more carefully
before I ask any further questions.
-Steven
> > I'm currently using:
> >
> > use CGI;
> > my $query = new CGI();
> >
> > What is the best way to define a global value like $query if I want to
> > 'use strict'. I really don't want to be passing $query to all my
> > subroutines. I could package define it as $main::query but that seems
> > awkward.
>
> http://perl.apache.org/guide/perl.html#Using_Global_Variables_and_Shari
>
> > -Steven
> >
> >
> > Jie Gao wrote:
> > >
> > > On Sat, 12 Aug 2000, stevenl wrote:
> > >
> > > > I am running Linux 2.2, Apache 1.3.12, mod_perl 1.24, and CGI.pm 2.70.
> > > >
> > > > If I declare a CGI variable using 'my' (see below) and use mod_perl, I
> > > > encounter problems with POST data. On subsequent entries in the form,
> > > > it continues to use the old data.
> > > >
> > > > The problem does not appear if I don't use 'my' (and therefore, unable
> > > > to 'use strict'), or if I disable mod_perl from my httpd.conf file.
> > > >
> > > > You can test this out with these files. First, run 'httpd -X'. Then
> > > > enter some data in the form. On the next submit, the data is not
> > > > changed.
> > > >
> > > > Note: The perl script displays the current HTML file plus what you
> > > > just entered.
> > > > ...
> > >
> > > http://perl.apache.org/guide/perl.html#my_Scoped_Variable_in_Nested_S
> > >
> > > Jie
> >
>
> _____________________________________________________________________
> Stas Bekman JAm_pH -- Just Another mod_perl Hacker
> http://stason.org/ mod_perl Guide http://perl.apache.org/guide
> mailto:stas@stason.org http://apachetoday.com http://jazzvalley.com
> http://singlesheaven.com http://perlmonth.com perl.org apache.org
Re: Problem with form data using mod_perl and CGI.pm
Posted by Stas Bekman <st...@stason.org>.
On Mon, 14 Aug 2000, stevenl wrote:
> Thanks. That seems to be the problem, accessing an outer lexical
> variable in an inner subroutine. I'm not quite sure I understand why
> Perl behaves this way. Java seems to handle this just fine with the
> expected behavior.
Because Perl != Java. And you are lucky that the last statement
returns true :) Of course the real explanation would require some reading
from you.
> I'm currently using:
>
> use CGI;
> my $query = new CGI();
>
> What is the best way to define a global value like $query if I want to
> 'use strict'. I really don't want to be passing $query to all my
> subroutines. I could package define it as $main::query but that seems
> awkward.
http://perl.apache.org/guide/perl.html#Using_Global_Variables_and_Shari
> -Steven
>
>
> Jie Gao wrote:
> >
> > On Sat, 12 Aug 2000, stevenl wrote:
> >
> > > I am running Linux 2.2, Apache 1.3.12, mod_perl 1.24, and CGI.pm 2.70.
> > >
> > > If I declare a CGI variable using 'my' (see below) and use mod_perl, I
> > > encounter problems with POST data. On subsequent entries in the form,
> > > it continues to use the old data.
> > >
> > > The problem does not appear if I don't use 'my' (and therefore, unable
> > > to 'use strict'), or if I disable mod_perl from my httpd.conf file.
> > >
> > > You can test this out with these files. First, run 'httpd -X'. Then
> > > enter some data in the form. On the next submit, the data is not
> > > changed.
> > >
> > > Note: The perl script displays the current HTML file plus what you
> > > just entered.
> > > ...
> >
> > http://perl.apache.org/guide/perl.html#my_Scoped_Variable_in_Nested_S
> >
> > Jie
>
_____________________________________________________________________
Stas Bekman JAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide http://perl.apache.org/guide
mailto:stas@stason.org http://apachetoday.com http://jazzvalley.com
http://singlesheaven.com http://perlmonth.com perl.org apache.org
Re: Problem with form data using mod_perl and CGI.pm
Posted by stevenl <st...@concentric.net>.
Thanks. That seems to be the problem, accessing an outer lexical
variable in an inner subroutine. I'm not quite sure I understand why
Perl behaves this way. Java seems to handle this just fine with the
expected behavior.
I'm currently using:
use CGI;
my $query = new CGI();
What is the best way to define a global value like $query if I want to
'use strict'. I really don't want to be passing $query to all my
subroutines. I could package define it as $main::query but that seems
awkward.
-Steven
Jie Gao wrote:
>
> On Sat, 12 Aug 2000, stevenl wrote:
>
> > I am running Linux 2.2, Apache 1.3.12, mod_perl 1.24, and CGI.pm 2.70.
> >
> > If I declare a CGI variable using 'my' (see below) and use mod_perl, I
> > encounter problems with POST data. On subsequent entries in the form,
> > it continues to use the old data.
> >
> > The problem does not appear if I don't use 'my' (and therefore, unable
> > to 'use strict'), or if I disable mod_perl from my httpd.conf file.
> >
> > You can test this out with these files. First, run 'httpd -X'. Then
> > enter some data in the form. On the next submit, the data is not
> > changed.
> >
> > Note: The perl script displays the current HTML file plus what you
> > just entered.
> > ...
>
> http://perl.apache.org/guide/perl.html#my_Scoped_Variable_in_Nested_S
>
> Jie
Re: Problem with form data using mod_perl and CGI.pm
Posted by Jie Gao <J....@isu.usyd.edu.au>.
On Sat, 12 Aug 2000, stevenl wrote:
> I am running Linux 2.2, Apache 1.3.12, mod_perl 1.24, and CGI.pm 2.70.
>
> If I declare a CGI variable using 'my' (see below) and use mod_perl, I
> encounter problems with POST data. On subsequent entries in the form,
> it continues to use the old data.
>
> The problem does not appear if I don't use 'my' (and therefore, unable
> to 'use strict'), or if I disable mod_perl from my httpd.conf file.
>
> You can test this out with these files. First, run 'httpd -X'. Then
> enter some data in the form. On the next submit, the data is not
> changed.
>
> Note: The perl script displays the current HTML file plus what you
> just entered.
> ...
http://perl.apache.org/guide/perl.html#my_Scoped_Variable_in_Nested_S
Jie