mdskrzypczyk has asked for the wisdom of the Perl Monks concerning the following question:
Then I have another script that contains a subroutine to modify this hash, as well as a call to said subroutine, I believe that this call gets run when the script is "required". This is how that script looks, lets call it config.pl:%GLOBAL = { dir1 => "/path/to/directory" dir2 => "/path/to/another" }
Now these previous scripts are never explicitly called, the main automation script looks like this, let's call it main.pl:[requires at the top] read_config_files(); sub read_config_files(){ #Do operations that read .txt files and load #info into the GLOBAL hash structure. }
So that after the config.pl is "required" it executes the read_config_files subroutine and the %GLOBAL hash looks like this:#A few requires... require "global.pl"; require "config.pl"; my first_directory = $GLOBAL{dir1}; etc...
But I get a "Global symbol "GLOBAL" requires explicit package name at main.pl line xx. My question is how can I properly have this working so that the error does not get thrown. Or, how can I convert the way this is working. Note that it is not just main.pl that tries to access members of %GLOBAL this way, there are a few other scripts that get their global information from this hash, therefore I'm trying to only have on copy of the hash and centralize all the info to that hash. UPDATE: I've managed to fix the problem by putting the hashes into a package! Thanks for all your help%GLOBAL = { dir1 = "/path/to/directory", dir2 = "/path/to/another", newstuff = "a string that was added", }
|
|---|