%main::GLOBAL = (
dir1 = "/path/to/directory",
dir2 = "/path/to/another",
);
####
sub read_config_files {
$main::GLOBAL{newstuff} = "a string that was added";
# etc
}
####
# this is file global.pl
use strict;
use warnings;
package GlobalStuff;
%GlobalStuff::GLOBAL = (
dir1 = "/path/to/directory",
dir2 = "/path/to/another",
);
# or, alternatively (same thing)
our %GLOBAL = (
dir1 = "/path/to/directory",
dir2 = "/path/to/another",
);
####
# this is file config.pl
use strict;
use warnings;
require 'global.pl';
read_GLOBAL();
print_GLOBAL(); # for example
sub read_GLOBAL {
$GlobalStuff::GLOBAL{new} = 'a string';
}
sub print_GLOBAL {
while ( my ($k, $val) = each %GlobalStuff::GLOBAL ) {
print "$k => $val\n";
}
}
####
require GlobalStuff;