Subject: | Weird behaviour due to deep references |
Date: | Sun, 17 Jul 2011 22:07:42 +1200 |
To: | bug-Config-General [...] rt.cpan.org |
From: | Mike Edmonds <mike [...] mlxvi.org> |
I wish to load configuration data from two files The first ParseConfig
uses default values in %defaultconfig and puts the result into %finalconfig.
The second ParseConfig also uses %defaultconfig for its default values.
However, it appears that this second ParseConfig alters the contents of
%defaultconfig, and in doing so alters the values in %finalconfig even
though %finalconfig is not otherwise assigned changed values.
I should imagine the problem is in passing references in the module.
Here is the minimal code to demonstrate my problem.
Please let me know if you want more info. I am running OpenBSD 4.7, Perl
5.10.1, Config::General 2.42
Mike
#! /usr/bin/perl
# built-ins
use strict ;
use warnings ;
use Config::General qw (ParseConfig) ;
use Data::Dumper ;
# the return value
my %finalconf = () ;
# the defaults updated
my %defaultconfig = () ;
print "First dump\n" ;
print Dumper(\%finalconf) ;
# lowest precedence file
my $configfile = '2.conf' ;
my %config = () ;
%config = ParseConfig(
-ConfigFile => $configfile,
-UseApacheInclude => 1,
-AutoTrue =>1,
-MergeDuplicateOptions => 1,
-MergeDuplicateBlocks => 1,
-DefaultConfig => \%defaultconfig,
) ;
%finalconf = %config ;
print "2nd dump\n" ;
print Dumper(\%finalconf) ;
# highest precedence file
$configfile = '3.conf' ;
%config = () ;
print "2.5rd dump\n" ;
print Dumper(\%config) ;
print "3rd dump\n" ;
print Dumper(\%finalconf) ;
%config = ParseConfig(
-ConfigFile => $configfile,
-UseApacheInclude => 1,
-AutoTrue =>1,
-MergeDuplicateOptions => 1,
-MergeDuplicateBlocks => 1,
-DefaultConfig => \%defaultconfig
) ;
print "Second config file\n" ;
print Dumper (\%config) ;
print "4th dump\n" ;
print Dumper(\%finalconf) ;
and the config files
2.conf:
<section1>
value4 This is in the second file and should not appear in the
third file at all
value5 This is in the second file
</section1>
3.conf
<section2>
# if this is not here then it will not be loaded
value1 1
</section2>
<section1>
value3 This is in the third file
value5 This is in the third file and should not appear alongside any
2nd file value
</section1>