Howdy all-

Quick question for the monks ... I have a hash that is basically setup as follows:
%myhash = ( 'aNumber.aCharacters' => { 'bNumber.bCharacters' => { 'one' => $valA, 'two' => $valB, 'three' => $valC, 'four' => $valD, 'five' => $valE, 'six' => $valF } } );
I can print information I wish by making a call such as:
print $myhash{'1.AB'}{'2.AB'}{'one'}, "\n";
What I'd like to be able to do is sort the hash by the first key (aNumber.aCharacters in the first example ... 1.AB in the second print example). If possible, I would then like to sort by the second key ... then I would print/use the rest of the availble information ('one','two',etc...).

My problem is that I have many random possibilties for the first and second hash keys ... they could be anything similar to the following:
1.AB 121.ABC1 52.ABC2
I would like the sort to be 'by number' of the digits before the period. I'm not sure a simple 'cmp' or '<=>' will do the trick ... and I can't figure out what to do. I searched for 'multidimensional hash sorting' on this site, but none of the questions really covered this question.

So, I suppose the short version of this question: how can I sort the above hash using the digits before the period of the first two hash keys? :)


In reply to sorting a complex multidimensional hash by envirodug

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.