in reply to Re^12: Config files
in thread Config files

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

Replies are listed 'Best First'.
Re^14: Config files
by sparkel (Acolyte) on Dec 15, 2004 at 03:24 UTC
    Hi Jenda,

    Thanks for the reply. The config::IniHash seems to convert all the keys and values from the config file to lowercase. Is there a way I can preserve the case changes that are seen in the config file after reading them in the hashes?
    Thank you

      Maybe it's time to read the module docs. There is an option that controls the case changes.

      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

        Thanks Jenda, I changed the code accordingly.