Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-03-29 01:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found