If you turned warnings on, you would see a warning about "variable cannot remain shared". The three basic solutions are to pass the session keys explicitly into every function, change my to our, or use the vars pragma to declare variables instead of using my.

OK, so that is the solution. What is the problem? That is a little more complex to explain.

Here is what Apache::Registry does. The first time your run your script it takes your CGI script, sticks a function around it, and calls eval. The second time it calls that function. The problem is that the functions in your script have global names, but the my variables that they are sharing with the rest of your script are private to the invocation of the outer wrapper function. So if you call the outer wrapper function twice (ie access the page twice), on the second call all of your functions are accessing the my variables from the first time you loaded that page.

If this confuses you, then review the code example at Re (tilly) 9: Why are closures cool? carefully and see if you an understand what it does. Replace the entire contents of outer() by your script, get rid of the anonymous functions that are meant to show you what is happening, and you have what is going wrong with your script.

If you still have trouble seeing it, just take my word that the problem is subtle and is basically impossible to come up with a really good fix to.

In that light, the three solutions correspondingly are to stop trying to share a private variable, make the private variable accessed actually be a global variable, and just plain make accessing a global variable OK.


In reply to Re: Apache::Session problem update... by Anonymous Monk
in thread Apache::Session problem update... by powerhouse

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.