<?xml version="1.0" encoding="windows-1252"?>
<node id="970563" title="Re: Sorting a hash of hashes" created="2012-05-15 01:05:30" updated="2012-05-15 01:05:30">
<type id="11">
note</type>
<author id="681898">
Utilitarian</author>
<data>
<field name="doctext">
The sort function takes an optional customised sort routine wherin you compare aspects of $a and $b. perldoc -f sort.

&lt;c&gt;
my %HoH = (
    SUB1 =&gt; {
        Test1 =&gt; {
            value1   =&gt; "2300",
            value2   =&gt; "0.01",
        },
        Test2 =&gt; {
            value1   =&gt; "5000",
            value1     =&gt; "0.34",
        },
    },
    SUB2 =&gt; {
        Test1 =&gt; {
            value1   =&gt; "2800",
            value2   =&gt; "0.05",
        },
    },
);
for my $sub_key (sort {$HoH{$a}{Test1}{value1} &lt;=&gt; $HoH{$b}{Test1}{value1} }keys %HoH){
   print "$HoH{$sub_key}{Test1}{value1}\n";
}
&lt;/c&gt;
&lt;b&gt;EDIT:&lt;/b&gt; &lt;i&gt;Corrected inline sort routine, original post made pre-coffee and shower :)&lt;/i&gt;
&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-681898"&gt;
&lt;c&gt;print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."&lt;/c&gt;
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
970560</field>
<field name="parent_node">
970560</field>
</data>
</node>
