in reply to Parameters not in order by using Config::Tiny

Hm, I am not sure why you would need them to be ordered.

You might want to order them during development so you could print and check to see that Config::Tiny is in fact processing your file properly, but in your program you should not be using them in a list anyway --- the whole point of an .ini file is to have named parameters ... so that you can avoid having to remember the order and having to use your params in order.

After you have tested, you will want to use Config::Tiny to slurp in your named parameters, and then just use them as you need them:

# in ini file [Section1] foo=bar baz=quux [Section2] perl=cool
# in program after reading file with Config::Tiny # note you can use them in any order you want my $perl = $ini->{'Section2'}->{'perl'}; my $baz = $ini->{'Section1'}->{'baz'}; my $foo = $ini->{'Section1'}->{'foo'};

Please state your reason for needing to sort your config parameters if this doesn't make sense to you.

Remember: Ne dederis in spiritu molere illegitimi!

Replies are listed 'Best First'.
Re^2: Parameters not in order by using Config:Tiny
by Corion (Patriarch) on Jul 06, 2015 at 14:29 UTC

    I think this requirement comes from the code in 1133314:

    foreach $ini_sect ( keys %ini_file ) { %$ini_sect = %{ $ini_file{$ini_sect} }; }

    This builds up a common structure from information distributed across different sections. I use a similar approach to have "common" and "specialized" sections:

    [GENERAL] FOO=bar TEMPLATE=./templates/mytemplate-v3.html [until-20150409] TEMPLATE=./templates/mytemplate-v2.html [until-20150307] TEMPLATE=./templates/mytemplate-v1.html

      OK, so you have options for your options based on things, like maybe the date. I must be dense today, but I can't see how sorting would help unless you have cleverly named your sections (as in your example) and then do:

      my $template; while ( I am looping through Sections) { next unless first half of name is 'until'; next unless date in second half of name hasn't passed yet; $template = this_Section->{TEMPLATE}; last; }

      But for the OP, how would

      foreach $ini_sect ( sort keys %ini_file ) { %$ini_sect = %{ $ini_file{$ini_sect} }; }

      be any better than

      foreach $ini_sect ( keys %ini_file ) { %$ini_sect = %{ $ini_file{$ini_sect} }; }

      ??

      Remember: Ne dederis in spiritu molere illegitimi!

        Yeah, I assume that the OP has some "clever" sorting of their sections, and the last one in the file should win.

        My use case is to allow for "evolution" of the input and output while still being able to process and output files with the older formats, according to the report date.