I was not aware of Tiny::Config::Ordered until today. However, the Hash::Ordered module v0.009 is quite nice IMO.

The following diff is all that's needed to preserve order transparently in Tiny::Config.

$ diff -u Tiny.pm.orig Tiny.pm --- Tiny.pm.orig 2015-07-06 12:51:54.000000000 -0400 +++ Tiny.pm 2015-07-06 13:02:22.000000000 -0400 @@ -3,6 +3,7 @@ # If you thought Config::Simple was small... use strict; +use Hash::Ordered; # Warning: There is another version line, in t/02.main.t. @@ -39,7 +40,8 @@ # Create an object from a string sub read_string { my $class = ref $_[0] ? ref shift : shift; - my $self = bless {}, $class; + tie my %obj, 'Hash::Ordered'; + my $self = bless \%obj, $class; return undef unless defined $_[0]; # Parse the file @@ -59,7 +61,10 @@ # Create the sub-hash if it doesn't exist. # Without this sections without keys will not # appear at all in the completed struct. - $self->{$ns = $1} ||= {}; + $self->{$ns = $1} ||= do{ + tie my %obj, 'Hash::Ordered'; + \%obj; + }; next; }

The output order matches the ini file (sections and elements).

$ perl test.pl [insert] SQL1 = insert into table <table1> SQL2 = insert into table <table2> SQL3 = insert into table <table3> SQL4 = insert into table <table4> [Truncate] SQL1 = truncate table <tablename1> SQL2 = truncate table <tablename2> [update] SQL1 = update into <table1> SQL2 = update into <table2>

I sent the link to the first post to both authors.

Kind regards, Mario


In reply to Re: Parameters not in order by using Config::Tiny by marioroy
in thread Parameters not in order by using Config::Tiny by bhushanQA

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.