use Exporter, see perldoc Exporter.
| [reply] [d/l] |
I like the method of reading in key/value pairs from a file to populate a hash. After all, even the package global symbol tables are just elaborate hashes.
But if you really want to execute the variable declarations into existance you can use the Exporter module to help. See the documentation for that module, as well as our, and perlmod. This response has already been offered by others in this thread.
I just wanted to add that you can use the fully qualified variable name even without Exporter.pm, and it won't break strictures. For example, if you have a variable in package "Variables", and the var is named "$hello", you could access it from package main like this: print $Variables::hello, "\n";
Modules give namespace segregation, but you're still able to get at that namespace from the outside.
| [reply] [d/l] |
You could always just put your key/value pairs into a file like this:
KEY1=VALUE1
KEY2=VALUE2
then slurp the values in at the beginning of your program:
open(F,"conf.ini");
my %config = {}'
while(<F>) {
(my $key,$value) = split /=/;
$config{"$key"} = $value;
}
close(F);
If you want %config global just declair it as our instead of my, or pass it around with Exporter.
| [reply] [d/l] [select] |