perlquestion
envirodug
Howdy all- <br><br>
Quick question for the monks ...
I have a hash that is basically setup as follows:
<code>
%myhash = ( 'aNumber.aCharacters' =>
{ 'bNumber.bCharacters' =>
{
'one' => $valA,
'two' => $valB,
'three' => $valC,
'four' => $valD,
'five' => $valE,
'six' => $valF
}
}
);
</code>
I can print information I wish by making a call such as: <br>
<code>
print $myhash{'1.AB'}{'2.AB'}{'one'}, "\n";
</code>
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...).
<br><br>
My problem is that I have many random possibilties for the first and second hash keys ... they could be anything similar to the following:
<code>
1.AB
121.ABC1
52.ABC2
</code>
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.
<p>
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? :)