develooper Front page | perl.beginners | Postings from March 2020

Re: Config::General save_file() not converting named block to nestedblock when there is only one block

Thread Previous | Thread Next
From:
Frans Spiesschaert
Date:
March 23, 2020 20:09
Subject:
Re: Config::General save_file() not converting named block to nestedblock when there is only one block
Message ID:
5fb1f36899aa866f7de757f4424ab6a69075785e.camel@yucom.be
Hi Andi,

I had a closer look at General.pm.
It turns out that when a configuration file has only one block,
Perl module Config::General puts it out as a named block on purpose.
See lines 1445 - 1457 of General.pm on this.
This behaviour has been introduced on Wed 18 Jul 2012 in version 2.51
of Config::General to fix Perl Bug #77667 as General.pm says at line 1447
(See https://rt.cpan.org/Public/Bug/Display.html?id=77667).
I also tried to reproduce Bug #77667 against version 2.63 of General.pm
and according to my findings, unfortunately this bug actually doesn't seem
te be fixed.

Thank you for helping me out with this problem.
Cheers,
Frans Spiesschaert


Andy Bach schreef op wo 26-02-2020 om 17:38 [-0600]:
> Yeah, no luck. I tried using an %options for the new() and set those
> various options to true[1], but made no difference. The interesting thing
> is it reads back just the single entry to the same hash, so maybe that's
> what "You need also to know that named blocks will be converted to nested
> blocks (which is the same from the perl point of view)" means.
> 
> a
> 
> [1]
> use strict;
> use warnings;
> use Config::General;
> use Data::Dumper;
> 
> my $datafilename = 'example.conf';
> my %confighash;
> #my $config = \%confighash;
> my $cconfig->{client}->{Bob}->{city} = 'Brussels';
> $cconfig->{client}->{Jane}->{city} = 'Antwerp';
> 
> my %options = (
>         -ConfigHash => $cconfig,
>         -ForceArray => 0,
>         -AutoTrue => 'yes',
>         -NormalizeBlock => 0,
>         -AllowMultiOptions => 0,
>         -MergeDuplicateBlocks => 1,
> );
> my $datafile = Config::General->new( %options );
> print "d: ", Dumper(\$datafile), "\n";
> $datafile->save_file($datafilename);
> 
> #print "c: ", Dumper(\$config), "\n";
> my $new_conf = Config::General->new($datafilename);
> print "r: ", Dumper(\$new_conf), "\n";
> 
> On Wed, Feb 26, 2020 at 2:28 PM Frans Spiesschaert <
> Frans.Spiesschaert@yucom.be> wrote:
> > Hi,
> > 
> > 
> > 
> > This is my exmple.pl
> > 
> > 
> > 
> > #!/usr/bin/perl -w
> > 
> > 
> > 
> > use strict;
> > 
> > use Config::General;
> > 
> > 
> > 
> > my $datafilename = 'example.conf';
> > 
> > my %confighash;
> > 
> > my $config = \%confighash;
> > 
> > $config->{client}->{Bob}->{city} = 'Brussels';
> > 
> > $config->{client}->{Jane}->{city} = 'Antwerp';
> > 
> > 
> > 
> > my $datafile = Config::General->new;
> > 
> > $datafile->save_file($datafilename, $config);
> > 
> > 
> > 
> > 
> > 
> > and that gives as expected the following result:
> > 
> > 
> > 
> > <client>
> > 
> >     <Jane>
> > 
> >         city   Antwerp
> > 
> >     </Jane>
> > 
> >     <Bob>
> > 
> >         city   Brussels
> > 
> >     </Bob>
> > 
> > </client>
> > 
> > 
> > 
> > 
> > 
> > but when I comment out in that file the line:
> > 
> > # $config->{client}->{Jane}->{city} = 'Antwerp';
> > 
> > 
> > 
> > I get the following result:
> > 
> > 
> > 
> > <client Bob>
> > 
> >     city   Brussels
> > 
> > </client>
> > 
> > 
> > 
> > But also in such a case I want to get 
> > 
> > 
> > 
> > <client> 
> > 
> >    <Bob>
> > 
> >         city   Brussels
> > 
> >    </Bob>
> > 
> > </client>
> > 
> > 
> > 
> > Is there a way to get this result in such a case?
> > 
> > 
> > 
> > 
> > 
> > -- 
> > 
> > Kind regards,
> > 
> > Frans Spiesschaert
> > 
> > 
> > 
> > -- 
> > 
> > To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> > 
> > For additional commands, e-mail: beginners-help@perl.org
> > 
> > http://learn.perl.org/
> > 
> > 
> > 
> > 
> > 



Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About