> I have a perl (non-modperl) program that needs some input data. Currently,
> it reads in the data by "require"ing another perl script that has
> statements to set the variables (as global variables). I did it this way
> so that I can easily edit the include file if I want to change values,
> and I can even put code in the include file to calculate values.
>
> But, I am finding that this does not work in modperl under "use strict".
> Apparently, code in a file called by require is not in the same variable
> scope. (If "use strict" is off, it works sometimes but other times the
> variables come out with the values from the previous invocation.)

You need to read up a little on modules and "require" in Perl5.

The quick and dirty solution is to use "do" instead of require.  That will
solve your immediate problem, but you'll still be reading the files every
time which might eventually become a performance hit.

What I do when I have things like config files is make actual unique
packages of them.  For example:

(In My/Module.pm)
package My::Module;
# don't use strict here
$foo = 7;

(In some other program)
use My::Module;
print "$My::Module::foo\n";

Honestly though, your example makes it look like you'd be better off with
dbm files and Tie::MLDBM or something.

- Perrin


Reply via email to