in reply to keeping variables separate

it has occurred at least once that data from one call to the handler has persisted to the next

Are you aware of the general issues with global variables and persistence in the mod_perl environment? (Just wondering...)

If not, see Sometimes it Works, Sometimes it Doesn't, or Global Variables Persistence, for example.

Replies are listed 'Best First'.
Re^2: keeping variables separate
by RandomWalk (Beadle) on Apr 20, 2009 at 17:41 UTC
    Thank you and kennethk for responding. Maybe I don't understand the libapreq2 module. But it looked simple enough.
    sub handler { # use Apache2::Request; is in startup.pl my $r = Apache2::Request->new(shift); my $shipaddr2 = $r->param("shipaddr2"); ...
    I don't understand how it would be possible for a "new" $r to retain a parameter from an old $r, even if, as kennethk suggests the parameter in the new $r has not been explicitly overwritten.

      I think it's not so much the $r object and its params, but rather some other data structure that's retaining the values.  At least, in your original post, it isn't clear where %ship_address comes from, how data gets into it, if it's global (which could be the problem), or if you do empty it on every request, etc.  In other words, it's hard to provide anything else than general hints without seeing the actual (complete) code...

        Thanks for your patience. I'll abstract: Perl handler to capture form submission data:
        sub handler { my $r = Apache2::Request->new(shift); my %in_cookies = Apache2::Cookie->fetch ($r); my $session = $in_cookies{"ID"} && $in_cookies{"ID"}->value; my $dbh = DBI->connect('DBI:mysql:mydb', 'myuser', 'mypasswd', { Ra +iseError => 1, AutoCommit => 1, PrintError => 1} ) or die $DBI::errst +r; my $shipaddr1 = $r->param("shipaddr1"); my $shipaddr2 = $r->param("shipaddr2"); my %ship_address = (addr1 => $shipaddr1, addr2 => $shipaddr2); unless ($dbh->selectrow_array("select count(*) from bill where sess +ion=?",undef,$session)){ # new entry $dbh->do("insert into bill (session) values(?)",undef,$session); while ( my ($key,$value) = each %ship_address ) { $dbh->do("update bill set ship$key = ? where session = ?", un +def, $value, $session); } }
        Difficulty: if the form does not contain data for shipaddr2 then shipaddr2 can contain data from a previous call to the handler.