$ cat conf.pl
#!/usr/bin/perl
use strict;
use warnings;
our %conf = (
foo => 'bar',
baz => 'quux'
);
__END__
####
$ cat ONE.pm
package ONE;
use strict; use warnings;
sub one {
our %conf;
require 'conf.pl';
return $conf{'foo'};
}
1;
##
##
$ cat TWO.pm
package TWO;
use strict; use warnings;
sub two {
our %conf;
require 'conf.pl';
return $conf{'baz'};
}
1;
##
##
$ cat 1137798.pl
#!/usr/bin/perl -w
use strict;
use ONE;
use TWO;
print ONE::one, "\n";
print TWO::two, "\n";
__END__
##
##
$ perl 1137798.pl
bar
Use of uninitialized value in print at 1137798.pl line 8.
##
##
$ cat ONE.pm
package ONE;
use strict; use warnings;
sub one {
our %conf;
#require 'conf.pl';
do 'conf.pl';
return $conf{'foo'};
}
1;
##
##
$ cat TWO.pm
package TWO;
use strict; use warnings;
sub two {
our %conf;
#require 'conf.pl';
do 'conf.pl';
return $conf{'baz'};
}
1;
##
##
$ perl 1137798.pl
bar
quux
##
##
$ cat conf.ini
[path]
foo=bar
some=other
[url]
baz=quux
less=more
##
##
$ cat 1137798-2.pl
#!/usr/bin/perl -w
use strict;
use Config::Tiny;
my $conf = Config::Tiny->read( 'conf.ini' );
print $conf->{path}->{foo}, "\n";
print $conf->{url}->{baz}, "\n";
__END__
##
##
$ perl 1137798-2.pl
bar
quux