Isn't what you need is a singleton object to store your values? Something that you'll call like this :
use MyModules::Config;
# here's the singleton magic:
# "new" recalls the existing instance if any.
my $conf=Config->new();
from each script. And the Config package would look like this :
package Config;
# this is the package variable to store
# the used instance
my $single;
# modules
use Carp;
sub new {
# usual stuff here...
my $proto = shift;
# create a new object if no instance currently active
unless ($single) {
$single = {} ;
# where to store data
$single->{options} = {};
}
bless($single);
return $single;
}
# here is the method to parse the conf. file
# and load the data in the Config object
sub parseconffile {
my $config = shift;
# here put something useful...
}
# end
1;
This way, all your modules can share the same config without passing any parameter around : just call
my $conf=Config->new() from each module, the first to call it will load the configuration data, the others will simply share that instance.
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.