On 9 October 2014 08:36, Hans Ginzel <h...@matfyz.cz> wrote: > I want to use one global hash variable for options or configuration > variables > like verbose, debug. I don't want to pass them to each function > or to almost each object. >
Indeed, Jim Gibson explains you can simply declare "our" in both files and the variable gets shared. Here is a contrived example that demonstrates that in a strange way: https://gist.github.com/kentfredric/cc1ddaabd2c698139869 You'll see in this example two files are natively accessing the same variable. Its ugly, but it works. Though I'd personally perfer something like this: https://gist.github.com/kentfredric/28d4c7831c9012950db4 That is, having the variable declared with "our" in the namespace that uses it, and having everywhere else that needs to manipulate it use its fullly qualified name, %Alpha::Shared to change its values. The difference would in practice be having code external to your main class doing $class::opts{'x'} = 'y'; Instead of relying on the convoluition of having to have 2 distinct sets of code in the same namespace across 2 files. Ideally I'd opt to find a way to eliminate the global variables where it makes sense to, but for some tasks ( like global defaults ), there isn't many better ways, so making it as logically clean as possible is desirable. ( Apologies if you can't read github gist links, I find email a very poor medium for code examples ) -- Kent *KENTNL* - https://metacpan.org/author/KENTNL