Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Config::General identical blocks sequence

by Skeeve (Vicar)
on Aug 01, 2011 at 07:10 UTC ( #917773=perlquestion: print w/replies, xml ) Need Help??
Skeeve has asked for the wisdom of the Perl Monks concerning the following question:

I already mailed the author but maybe someone here also know the answer?

If I have identical blocks in a Config::General configuration file like the one in my example below. What will be the sequence in which my script receives them? Will it be document order? From my test it seems to be the case, but I couldn't find anything about the order in the documentation.

here is my example code:

use strict; use warnings; use Data::Dumper; use Config::General; my $conf = new Config::General( -String => <<'CONFIG' ); <option> value 1 </option> <option> value 2 </option> CONFIG print Dumper( { $conf->getall() } ); exit;
On my system the result is
$VAR1 = { 'option' => [ { 'value' => '1' }, { 'value' => '2' } ] };
Which is the document order I expected. But can I be sure that it will always be the case? Even in the next release of Config::General?


Replies are listed 'Best First'.
Re: Config::General identical blocks sequence
by Anonymous Monk on Aug 01, 2011 at 07:50 UTC

      I'm not so sure, the order is not mentioned in the section anonmonk cited. The example it gives is introduced with "you would end up with a data structure like this", not "you would end up with this data structure" or "exactly like this". While it isn't likely that the writer of the documentation thought about this question when he wrote that sentence, it is also unlikely that he thought about specifying the order at all

Re: Config::General identical blocks sequence
by Mr. Muskrat (Canon) on Aug 02, 2011 at 19:34 UTC

    From the docs, "You may have more than one line of the same option with different values." and "You will get a scalar if the option occurred only once or an array if it occurred more than once."

    If you look at the code for Config::General you will see that it's creating an array when it finds two or more of the same option with different values and pushing the values into an array. So yes, the order will be same.

Re: Config::General identical blocks sequence
by ikegami (Pope) on Aug 02, 2011 at 19:44 UTC
    It's naturally easy to keep them in order, and it's a feature I suspect the maintainers want to keep. I don't see this changing.
Re: Config::General identical blocks sequence
by Skeeve (Vicar) on Aug 03, 2011 at 17:40 UTC

    You both are right but as long as it is not documented, the implementer is free to change the order without notice.

    Sure it's easy to maintain document order and it's (to my understanding) the "natural" order.

    But anyway: Thomas replied and I think he will document it.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://917773]
Approved by Corion
Front-paged by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2018-05-27 10:18 GMT
Find Nodes?
    Voting Booth?