in reply to Global Variables Not Acting Global

What's your problem?

Please demonstrate it in a condensed piece of code and plz make clear if your talking about one invocation of your CGI or persistent sessions.

In the latter case (i.e. mod-perl, FCGI, ...), there are issues regarding package and lexical variables.

Cheers Rolf

Replies are listed 'Best First'.
Re^2: Global Variables Not Acting Global
by rbhyland (Acolyte) on Apr 21, 2011 at 12:28 UTC
    I was expecting a global variable, $CurIDPtr, to maintain its value like a session variable. anonymized user 468275 put his finger on the problem.
      here a simple example of a persistent variable $count while using CGI::Fast

      use strict; use warnings; use CGI::Fast; our $count = 0; while ( my $q = new CGI::Fast ) { $count++; print $q->header( "text/plain" ), "You are request number $count. Have a good day!\n"; }

      (taken from O'Reilly's CGI book and modernized )

      Cheers Rolf

        I think it's worth noting that for this to work reliably, you'd have to make sure that the web server side end of FastCGI (such as mod_fcgi, mod_fastcgi) is configured to run only one instance of the respective process.  Otherwise, different requests could happen to be routed to different processes, which would produce unexpected results. Not to mention the confusion that would result from different people using the same CGI program and state variables.  The same problem would also occur with several apache/mod_perl instances running...

        In other words, the easiest (and proper) way to achieve persistence across requests is to use sessions (CGI::Session), which makes your data being stored/retrieved independently of the process handling the current request.