F
Fred
The two subs below are in a package named Mypkg.pm.
The LoadConfig sub uses AppConfig. In this sub I
can print the host variable using $config->host().
So I added the line our $hostx = $config->host(),
to assign this to $hostx. Now in the TestSub sub,
I try and print Mypkg::LoadConfig::hostx, but it
never prints. How can I access hostx from the
TestSub subroutine?
-Thanks
sub LoadConfig
{
shift @_;
my ($cfgfile, $prn) = @_;
my $config = '';
$config = AppConfig->new(
{
CASE => 1,
PEDANTIC => 0,
CREATE => 1,
ERROR => sub {},
GLOBAL => { ARGCOUNT => ARGCOUNT_ONE }
}
);
$config->file($cfgfile);
####### Can't access this below in DBConnect ########
our $hostx = $config->host();
if ($prn eq 'p') {
print "Configuration file: $cfgfile\n";
print "dbname:\t\t".$config->dbname()."\n";
print "host:\t\t".$config->host()."\n";
print "port:\t\t".$config->port()."\n";
print "username:\t".$config->username()."\n";
}
}
sub TestSub
{
LoadConfig('/etc/my.conf');
######## Cannot print host variable from LoadConfig above ########
print Mypkg::LoadConfig::hostx;
}
The LoadConfig sub uses AppConfig. In this sub I
can print the host variable using $config->host().
So I added the line our $hostx = $config->host(),
to assign this to $hostx. Now in the TestSub sub,
I try and print Mypkg::LoadConfig::hostx, but it
never prints. How can I access hostx from the
TestSub subroutine?
-Thanks
sub LoadConfig
{
shift @_;
my ($cfgfile, $prn) = @_;
my $config = '';
$config = AppConfig->new(
{
CASE => 1,
PEDANTIC => 0,
CREATE => 1,
ERROR => sub {},
GLOBAL => { ARGCOUNT => ARGCOUNT_ONE }
}
);
$config->file($cfgfile);
####### Can't access this below in DBConnect ########
our $hostx = $config->host();
if ($prn eq 'p') {
print "Configuration file: $cfgfile\n";
print "dbname:\t\t".$config->dbname()."\n";
print "host:\t\t".$config->host()."\n";
print "port:\t\t".$config->port()."\n";
print "username:\t".$config->username()."\n";
}
}
sub TestSub
{
LoadConfig('/etc/my.conf');
######## Cannot print host variable from LoadConfig above ########
print Mypkg::LoadConfig::hostx;
}