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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.