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):

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