I'm using Config::Simple for my App config, I have created
Stats_feeder.cfg
[stats_interval]
[stats_interval]
1m = 60
15m = 900
script.pl
my $cfg = new Config::Simple('stats_feeder.cfg') or die Config::Simple->error();
my $hash = $cfg->get_block('stats_interval');
print Dumper($hash);
# perl stats_feederv2.pl
$VAR1 = {
'1m' => '300',
'15m' => '900',
'60m' => '3600',
'30m' => '1800'
};
$val = $cfg->param('1m');
foreach my $key ( keys %$hash )
{
print "key $key value $hash{$key}\n";
}
Global symbol "%hash" requires explicit package name at stats_feederv2.pl line 42.
Execution of stats_feederv2.pl aborted due to compilation errors.
$hash{key}
syntax that you use for printing the key's value works when you have a named hash: %hash
. In your case, you have an anonymous hash, under a hash reference.
To access the key's value in such a case, you should use this syntax: $hash_ref->{key}
. Change:
print "key $key value $hash{$key}\n";
To:
print "key $key value $hash->{$key}\n";