Can I assume your original data is sorted, and you really just want to maintain the original order? Then you want something like Tie::IxHash. There are several of those modules, like Tie::Hash::Indexed, which is written in XS (the former is in Pure Perl) and thus, probably faster.

Perhaps you do want your hash to be automatically sorted. In that case, you might be interested in something that works like a hash, but internally keeps the keys sorted, something like a binary search tree. I don't know immediately of something that you could use instead of a hash, but perhaps, assuming your hash keys are always integers, a Judy Array might work for you. There's an XS implementation for Perl in Tie::Judy. The docs there say: "the keys here are in bit-wise SORTED order".


In reply to Re: split and sort functions by bart
in thread split and sort functions by zkeeper

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.