Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Variable scoping and mod_pel/Apache::ASP

by lo_tech (Scribe)
on Nov 01, 2001 at 22:59 UTC ( [id://122629]=perlquestion: print w/replies, xml ) Need Help??

lo_tech has asked for the wisdom of the Perl Monks concerning the following question:

Fellow monks, I've got a skull-scratcher that is beyond me. Any assistance would be greatly appreciated.

I have an Apache::ASP page that takes user input and posts it back to itself. My problem is that about every 3-5 times that I submit the form, the SENTDATA var isnt accessable from check_login_output.

Note: it works most of the time and I'm confused because this behavior is intermittent.

Here's the code

<% use CGI ':cgi-lib'; my %SENTDATA = Vars; print join('|', "1",$SENTDATA{UID},\%SENTDATA,"<br>"); if (! $SENTDATA{UID}) { # no passed userid, show the input screen print join('|', "2a",$SENTDATA{UID},\%SENTDATA,"<br>"); &amp;amp;amp;amp;amp;amp;amp;show_login_input(); } else { print join('|', "2b",$SENTDATA{UID},\%SENTDATA,"<br>"); &amp;amp;amp;amp;amp;amp;amp;check_login_input(); } $Response->End(); sub check_login_input { print join('|', "3",$SENTDATA{UID},\%SENTDATA,"<br>"); } sub show_login_input { # html input <SENTDATA method='POST'> %>

Here's the output from when it works:

1|506651|HASH(0x20656624)| 2b|506651|HASH(0x20656624)| 3|506651|HASH(0x20656624)|

Here's the output from when it doesn't work:

1|506651|HASH(0x20672eb0)| 2b|506651|HASH(0x20672eb0)| 3||HASH(0x202e110c)|

Now for the Question(s):

  • 1. Why is SENTDATA only avaialable to check_login_input() intermittently?
  • 2. When it does fail, why am I not getting an error in check_login_input() for the use of an undeclared var?

Misc Config Info
Perl/5.6.1
Apache/1.3.20 (Unix)
mod_perl/1.26
Apache::ASP/2.25
use strict and Taintcheck set to true in httpd.conf
CGI.pm is the one that shipped with 5.6.1, I think it's 2.752

Replies are listed 'Best First'.
Re: Variable scoping and mod_pel/Apache::ASP
by perrin (Chancellor) on Nov 02, 2001 at 01:38 UTC
    You're creating closures. %SENTDATA is a lexical (my) variable, and check_login_input() will keep a private copy of the first version it sees in there. It works some of the time because you have multiple Apache processes going here and some of them saw it with data the first time while others saw it empty.

    To fix this, either make %SENTDATA a global (use vars) or pass it to your subroutines (by reference).

Re: Variable scoping and mod_pel/Apache::ASP
by brother ab (Scribe) on Nov 02, 2001 at 13:01 UTC

    Looks like it is the most frequent trouble people moving from CGI to mod_perl bump into. At least so it is for my knowlege.

    Fortunately, there exist excellent mod_perl guide. See especially section about closures.

    -- brother ab

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://122629]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2024-03-28 12:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found