Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Perl: the Markov chain saw
 
PerlMonks  

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?


s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Comment on Config::General identical blocks sequence
Select or Download Code
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 (Abbot) 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.


    s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
    +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://917773]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (10)
As of 2014-04-16 07:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (417 votes), past polls