--- Begin Message ---
Andy Bach schreef op wo 26-02-2020 om 15:30 [-0600]:
> Huh.  Seems the docs would say the opposite

Yes indeed, the docs do say so.
But you should try my exampl.pl to find out that it fails to do so when
there is only one block.
And I have no clue on how to get the desired result.
So any hint is welcome.

>     save_file()
>         Writes the config hash back to the hard disk. This method takes
> one or
>         two parameters. The first parameter must be the filename where
> the
>         config should be written to. The second parameter is optional, it
> must
>         be a reference to a hash structure, if you set it. If you do not
>         supply this second parameter then the internal config hash, which
> has
>         already been parsed, will be used.
> 
>         Please note that any occurrence of comments will be ignored by
>         getall() and thus be lost after you call this method.
> 
>         You need also to know that named blocks will be converted to
> nested
>         blocks (which is the same from the perl point of view). An
> example:
> 
>          <user hans>
>            id 13
>          </user>
> 
>         will become the following after saving:
> 
>          <user>
>            <hans>
>               id 13
>            </hans>
>          </user>
> 
> 
> 
> On Wed, Feb 26, 2020 at 2:28 PM Frans Spiesschaert <
> frans.spiesscha...@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-unsubscr...@perl.org
> > 
> > For additional commands, e-mail: beginners-h...@perl.org
> > 
> > http://learn.perl.org/
> > 
> > 
> > 
> > 
> > 



--- End Message ---
-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/

Reply via email to