in reply to Modifying/Accessing hash in separate script

Try to LOCK the hash after it has the config info loaded.

Hash::Util has the lock_hash_recurse method to enforce such a thing.

That way, you can catch offenders that try to modify the config, and take appropriate action.

        "Despite my privileged upbringing, I'm actually quite well-balanced. I have a chip on both shoulders."         - John Nash

  • Comment on Re: Modifying/Accessing hash in separate script

Replies are listed 'Best First'.
Re^2: Modifying/Accessing hash in separate script
by mdskrzypczyk (Novice) on Jul 22, 2015 at 18:42 UTC
    I'm afraid you may have misinterpreted what I'm trying to accomplish. There's only going to be one subroutine modifying the has, that's okay. It's a matter of satifying the use strict/use warnings when I try to access members of the hash in other scripts.

      Can you post a bit of how the hash is declared in the one script, and how it is used in the other?

      Maybe you have

      # config.pl $config{ base_dir } = '/opt/myapp'; $config{ bin_dir } = "$config{ base_dir }/bin";

      ... and then in the main program(s):

      require 'config.pl'; print "My config is $config{ base_dir }\n";

      Then you can add use strict to both files if you add use vars '%config'; to both of them.

        I've added some code to help, thanks for your consideration