F
Fred
According to the docs, if you define a variable using the
"use vars" pragma in a perl module, then that variable should
be available across the entire .pm module. Listed below I have
an excerpt from a module named test.pm. The $host variable is
defined with the "usr vars" pragma, but I can't access it from
the subroutine test() below.
Essentially what I want to do is use AppConfig to read values
from a configuration file like host, port, etc., then have
them available to other subroutines when called. I'm trying
to avoid having to read the config file every time a subroutine
is called. Is this possible without using the Storable module?
-Thanks
our @EXPORT = qw(
LoadConfig
);
our $VERSION = '0.01';
use vars qw($host $VERSION @ISA @EXPORT @EXPORT_OK);
sub LoadConfig
{
shift @_;
my ($cfgfile) = @_;
our $config = AppConfig->new(
{
CASE => 1,
PEDANTIC => 0,
CREATE => 1,
ERROR => sub {},
GLOBAL => { ARGCOUNT => ARGCOUNT_ONE }
}
);
$config->file($cfgfile);
my $host = $config->host();
#####The $host variable is assigned here
print "HOST IN LoadConfig: $host\n";
}
sub test
{
######I can't reference $host in different subroutine
print "IN TEST() HOST IS: $host\n";
}
"use vars" pragma in a perl module, then that variable should
be available across the entire .pm module. Listed below I have
an excerpt from a module named test.pm. The $host variable is
defined with the "usr vars" pragma, but I can't access it from
the subroutine test() below.
Essentially what I want to do is use AppConfig to read values
from a configuration file like host, port, etc., then have
them available to other subroutines when called. I'm trying
to avoid having to read the config file every time a subroutine
is called. Is this possible without using the Storable module?
-Thanks
our @EXPORT = qw(
LoadConfig
);
our $VERSION = '0.01';
use vars qw($host $VERSION @ISA @EXPORT @EXPORT_OK);
sub LoadConfig
{
shift @_;
my ($cfgfile) = @_;
our $config = AppConfig->new(
{
CASE => 1,
PEDANTIC => 0,
CREATE => 1,
ERROR => sub {},
GLOBAL => { ARGCOUNT => ARGCOUNT_ONE }
}
);
$config->file($cfgfile);
my $host = $config->host();
#####The $host variable is assigned here
print "HOST IN LoadConfig: $host\n";
}
sub test
{
######I can't reference $host in different subroutine
print "IN TEST() HOST IS: $host\n";
}