Since you did not specify it, I assume you want the comparison done on "value1" only. Based on that, here is the code:
my %rehash; for my $SUBNAME (sort keys %HoH){ for my $testname (sort keys %{ $HoH{$SUBNAME} }) { my $val = $HoH{$SUBNAME}{$testname}{value1}; if (exists $rehash{$testname}{$SUBNAME}{value1} and $rehash{$testname}{$SUBNAME}{value1} > $val){ # Do not update - greater value exists }else{ $rehash{$testname}{$SUBNAME} = $HoH{$SUBNAME}{$testname}; } } } for my $testname (sort keys %rehash){ print "For $testname:\n"; for my $SUBNAME(sort keys %{ $rehash{$testname} }){ print " $SUBNAME has " , map( {" $_=$rehash{$testname}{$SUBNAME}{$_};"} sort keys %{$r +ehash{$testname}{$SUBNAME}}), ,"\n"; } } __OUTPUT__ For Test1: SUB1 has value1=2300; value2=0.01; SUB2 has value1=2800; value2=0.05; SUB3 has value1=2700; value2=0.25; For Test2: SUB1 has value1=5000; value2=0.34; SUB2 has value1=5500; value2=0.34; SUB3 has value1=5800; value2=0.45; For Test3: SUB1 has value1=3000; value2=0.10; For Test4: SUB1 has value1=7000; value2=0.33;
At this point, your original problem has been long solved, so please make further enhancements yourself.

             I hope life isn't a big joke, because I don't get it.
                   -SNL


In reply to Re^5: Sorting a hash of hashes by NetWallah
in thread Sorting a hash of hashes by mrc

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.