Spidy has asked for the wisdom of the Perl Monks concerning the following question:

So, I have some files. Not all of them are in the same folders.

One of them, inside it's BEGIN{} block, has this piece of code:
%config = do "../config.cgi" or die("Error: $!");
Which is, of course, supposed to 'do' the configuration loader file, in the folder above it. This is the configuration loader file:
our %config = do "filename" or die("can't recreate config info: $!"); return %config;
And, inside our actual config FILE:
%config = ( 'logging_enabled' => 1, 'crypt_salt' => 'xQ' );
However, the problem is that the first file isn't having anything loaded into it's %config hash. Nothing at all is in there. Does anyone know why this is?

Thanks,
Spidy

Replies are listed 'Best First'.
Re: Having a problem with do
by Tanktalus (Canon) on Jun 02, 2006 at 04:01 UTC

    Is the current directory the one you think it is?

    Personally, there are a couple things that scare me here...

    1. Using .. to load a file. I try to use full paths when I can. When I can't, I tightly control the current working directory. And reset it when I'm done.
    2. Using do instead of require or use. If you're going to reuse the code, please please please put it in a module.
    Just a thought.

Re: Having a problem with do
by Joost (Canon) on Jun 02, 2006 at 10:23 UTC