Others have mentioned the Tie::IxHash method for causing a hash to remember its insertion order. But I just wanted to mention what hasn't already been said: a Tie::IxHash should only be done after careful consideration of the fact that this approach carries with it some positives, and some negatives.

If you think of your consideration process as a balance sheet, on the positive side, you get an ordered hash. On the negative side, you get a less speed efficient and less memory efficient hash. You trade speed and memory for convenience. That may be a worthwhile trade for you. Or it might be a dealbreaker. Just as long as you're aware of the issues, you can make the right decision for your particular situation.


Dave


"If I had my life to live over again, I'd be a plumber." -- Albert Einstein

In reply to Re: Ordered Hashes by davido
in thread Ordered Hashes by Sprad

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.