Dear monks, I'd like to ask for help understanding this problem.

The context is a mod_perl Apache http server and DBI access to mysql.

The action of an html form is a perl handler. The handler starts off by getting the request object and reading an identifying cookie:

sub handler { my $r = Apache2::Request->new(shift); my %in_cookies = Apache2::Cookie->fetch ($r); my $session = $in_cookies{"ID"} && $in_cookies{"ID"}->value; ...
The handler takes arguments from $r->param and writes them to a mysql table by means of a database handle obtained from DBI->connect.

The problem: it has occurred at least once that data from one call to the handler has persisted to the next and has been written to a record belonging to a different session. Specifically, this section of code misfired, the hash %ship_address somehow retaining data from its previous assignment:

while ( my ($key,$value) = each %ship_address ) { $dbh->do("update bill set ship$key = ? where session = ?", undef, $ +value, $session);
The 2nd customer was very surprised to learn he lived on the 5th floor of a one story house...

I am uncertain how to isolate the problem. Can you help? Thanks.


In reply to keeping variables separate by RandomWalk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.