in reply to Re^5: How not to use "our"?
in thread How not to use "our"?

Ah, I understand now. Many thanks :)

With your approach - declaring variables with "our" - would it lead to problems with mod_perl? I've never used mod_perl before, but I read that you can't have globals when using mod_perl.

Suppose I export the hashed variables (as in my approach), would that cause problems in a mod_perl environment?

Replies are listed 'Best First'.
Re^7: How not to use "our"?
by JavaFan (Canon) on Nov 30, 2010 at 15:22 UTC
    Whether you can have, or cannot have, package variables is unrelated to whether the package variables are scalars or hashes, or whether they are exported or not.

    Note also that if mod_perl means you cannot have globals, it would mean you cannot have Perl. Certain global variables always exist.

    The issue with mod_perl is that modules get only compiled "once" (well, typically, once in the life time of an Apache child), and not each time the program is run. This means "globals" may not get (re)initialized. But that is not the same as package variables!. File scoped lexicals and sub-bounded state variables won't get (re)initialized either. And package variables that get initialized in your mod_perl program do get initialized.

    The mod_perl issue all has to do when certain code is run - not whether variables are package variables or lexicals.

      Thanks for above, JavaFan!

      I'm trying to grasp the concept before I use mod_perl, so please bear with me if my questions sounded silly.

      I'm trying to make sense of 'The issue with mod_perl is that modules get only compiled "once"'. Let's say I've a variable (my $score) in a module that stores the score of a user, say, playing a game. When another user comes online, or for that matter, when several users appear, will the variable correctly store the value for each of the user when the script (that calls the said module) is run?

        How should I know? As I said, it all depends on when you assign to $score, and what its scope is.