I have been working with Mod_Perl for a few years now and have been fairly successful.  I thought that I had a fair understanding of how things worked until today.  I’m using Mod_Perl version 1.0 and I’m just using the Apache::Registry to speed up regular Perl scripts.

 

Problem #1:

==============

 

I forgot to initialize a global variable!  Bummer.  In my code I declare global variables like this:

 

use strict;

 

package mylib;

 

# Globals: Set them below

$mylib::strGlobalStudyName = "";

 

I then initialize them with this:

 

sub InitializeMylibGlobals

{

$mylib::strGlobalStudyName = "";

}

 

I call this initialize function every time the script runs.  Anyway I forgot and so one of my global variables was not initialized.  I was shocked when I discovered the value from the global variable from another user stick around.  I know global variables are bad but sometimes you have to use them.  What are some good work-a-rounds? 

 

But my big question is, is it safe to use global variables at all?  Am I guaranteed that if I initialize them at the start of my script that they won’t be set by another process before I use them later in my script??????????????? 

 

Problem #2:

==============

I realize that when a Perl library file is “required” in goes into memory.  And then the next time that that library is needed it will just be used from memory and not have to be read in again.  I thought that only files that were “required” went into memory.  Today I was surprised when it appeared that my main script was in memory.  The main file that the web users hit in their URL is called “MyAdmin.pl”.  This file looks like this:

 

 

use strict;

 

admin::main();

 

package admin;

 

sub main

{

 

}

1;

 

This file is not required by any other script.  On my machine I had two different versions of “MyAdmin.pl”.  They were in different locations so:

 

http://www.mysite.com/one/MyAdmin.pl

 

and

 

http://www.mysite.com/two/MyAdmin.pl

 

Well, the script in directory “one” started to run the version in directory “two”.  I would understand this behavior if their was a “required” library file, but in this case there are two main files.  Does the package “admin” stay in memory even though I did not “require” it?  I have been lead to believe that it does not stay in memory because when I update MyAdmin.pl with new code I see the new behavior without having to reset Apache.

 

I would appreciate any help.

 

Thanks.

 

 

 

Reply via email to