http://www.perlmonks.org?node_id=997940


in reply to mod_cgid, CGI::Fast share values between different scripts?

Your approach goes wrong on several levels.
First of all, you're not supposed to store database handles as persistent variables. It's a bad, bad idea. Use Apache::DBI and mod_perl for that. If you do not want to use DBI directly, I believe DBIx::Class does persistence as well.
Next, it won't work like you expect it to. Say that user 1 comes and accesses a.cgi. Along comes user 2 and accesses a.cgi as well. User 1 and 2 move on to b.cgi, but then user 1 decides to go back to a.cgi. But what user 1 sees is not their data -- it is that of user 2, if even that. This will not go well, and is dangerous for sensitive data.

Instead, what it sounds like you want is a session with a storage backend. Consider CGI::Session, for example, or Apache::Session(X) for mod_perl.
If you want to make something that will go beyond just simple CGI scripts and want something extensible and robust, consider Catalyst or Mojolicious(::Lite). Feeling adventurous? Try Combust, which powers many perlweb sites, IIRC. I personally prefer Catalyst, but you might like something else.

HTH


Update: Replaced <pre /> with <code />, because that did not look right at all.

~Thomas~
confess( "I offer no guarantees on my code." );

Replies are listed 'Best First'.
Re^2: mod_cgid, CGI::Fast share values between different scripts?
by Anonymous Monk on Oct 09, 2012 at 07:36 UTC
    didn't i mentioned this is for a FastCGI environment? it's not a mod_perl environment and will not become one.

    and yes, i like to share the exact same data (memory) between different users and scripts.

    but thanks for your hints. IPC::ShareLite's shared mem does all i need.

      didn't i mentioned this is for a FastCGI environment? it's not a mod_perl environment and will not become one.
      I was providing an example that could potentially work for both environments, not just for you, but for anybody on the internet who happens to come across your question and my answer.
      That is beside the point anyways, as sharing variables willy-nilly and without care will lead to disastrous results. You don't have to believe me. Try it out for yourself. Don't take my word -- or anybody else's -- for what it's worth, I could be lying. This is the internet.

      ~Thomas~
      confess( "I offer no guarantees on my code." );