I told you the code looks into the current section if you do not specify the section name. I don't think it's wise to search for the values in other sections, but if you want the code can easily be changed to do that.

$value =~ s{%(?:\[([^\]%]+)\])?([^%]*)%}{ if ($2 eq '') { '%' } elsif ($1 eq '') { if (exists $INIhashref->{$sectionname}{$2}) { $INIhashref->{$sectionname}{$2} } else { my $found; foreach my $section (values %$INIhashref) { if (exists $section->{$2}) { $found = $section->{$2}; last; } } $found } } else { $INIhashref->{$1}{$2} } }ge;
With this if the user doesn't specify the section name then the option is first looked up in the current section and then in all already read sections. If the option was specified in several versions then you end up with the value from a "random" one. Hashes do not preserve order so the code cannot tell in what order were the section in the INI file.

If you did want to take the into consideration you'd have to instruct Config::IniHash to store the order in @{$config->{'__SECTIONS__'}} using the sectionorder parameter. See the docs. You'd then loop through the @$INIhashref{@{$INIhashref->{'__SECTIONS__'}}} instead of <code>values %$INIhashref. (The scary looking code in the previous line is a hash slice, using the array referenced by $config->{'__SECTIONS__'} as the list of keys.

Jenda
We'd like to help you learn to help yourself
Look around you, all you see are sympathetic eyes
Stroll around the grounds until you feel at home
   -- P. Simon in Mrs. Robinson


In reply to Re^13: Config files by Jenda
in thread Config files by sparkel

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.