http://qs1969.pair.com?node_id=286426

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

Good Evening,

I do have a probably simple problem but I just can not fix it. Here is my point:

I have an own module (package) which is designed to create object-instances. In this package I have a "global" variable named %config. I put the word 'global' in quotation marks, because I think that's where my problem begins. I tried my, our and double-colon namespace syntax. This hash should be equal for all created objects. So far, so good. Every object is able to access %config. The package now contains a subroutine for reloading the (changed) config-file and storing its contents into %config after parsing. At this point the hash is either empty (or not accessible anymore?) for all object instances or did not change at all. That depends on how I declared the global hash. As you can see the sub-routine is the same as the one I call at the beginning of the package (to fill %config). I even tried almost-nonsense combinations in my desperation, but I am sure it is easily possible in any other way.

My program is very complex so I chose to post a simple (pseudo) takeout - The substantial is of importance for me. The _parse_file() sub-routine is purposely missing in order to keep clarity.
package Foo; use strict; my %config = _fill_config(); sub new { my $proto = shift(); my $status = shift() || 'normal'; my $package = ref($package) || $package; my $self = { status => $status }; bless($self, $package); return $self; } sub change_config { my $self = shift(); return unless $self->{status} ne 'admin'; %config = _fill_config(); } sub _fill_config { my %temp = _parse_file('config.cfg'); return %temp; }
Thank you very much for your suggestions, Monks.

BioHazard
reading between the lines is my real pleasure