Please help me resolve this issue
pre_package_config.pm
use strict;
our %pre_pkg_configs;
$pre_pkg_configs{locDbList}=['default','default_test'];
second.pl
#!/usr/bin/perl
use Expect;
use strict;
our %pre_pkg_configs;
my $pre_pkg_file = './pre_package_config.pm';
eval {require $pre_pkg_file};
foreach my $db ( $pre_pkg_configs{locDbList} ){
print $db;
}
Output:
ARRAY (0x10092ae88)
Should have been:
default
default_test
$pre_pkg_configs{locDbList}is a single (scalar) value. Iterating over it would simply give you that one value (which happens to be a reference to an array). If you want to iterate over the contents of that array, you need to dereference:Note that this will output
defaultdefault_test, notdefault default_test. The easiest way to get the latter would be:To learn more about references, see
perldoc perlreftut.(Also, you should
use warnings;in every file in addition touse strict;.)