I'm trying to sort the keys of the following hash:
$VAR1 = { 'GetNext -------------- 11.254.49.217:1.3.6.1.2.1.4.20.1.2' => { '1.3.6.1.2.1.4.20.1.3' => [ [ 'ipAdEntNetMask', 1 ] ], 'Min_Time' => '16:29:08.03', 'Error_Status' => 'No error', 'Avg_Time' => undef, 'Min_Time_Diff' => '9:59:59.9', 'Total_Time' => '0:00:00.0', 'Last_Time' => '16:29:08.03', 'Max_Time' => '16:29:08.03', '1.3.6.1.2.1.4.20.1.2' => [ [ 'ipAdEntIfIndex', 1 ] ], 'Max_Time_Diff' => '00:00.0' }, 'Response -------------- 11.254.49.217:1.3.6.1.2.1.4.20.1.3.0.0.0.0' + => { 'Error_Status' => 'No error', 'Total_Time' => '0:00:00.0', 'Last_Time' => '16:29:08.04', '1.3.6.1.2.1.4.20.1.4.0.0.0.0' => [ [ 'ipAdEntBcastAddr.0.0.0.0', 1 ] ], 'Max_Time_Diff' => '00:00.0', 'Min_Time' => '16:29:08.04', 'Avg_Time' => undef, 'Min_Time_Diff' => '9:59:59.9', '1.3.6.1.2.1.4.20.1.3.0.0.0.0' => [ [ 'ipAdEntNetMask.0.0.0.0', 1 ] ], 'Max_Time' => '16:29:08.04' }, 'GetNext -------------- 11.254.49.217:1.3.6.1.2.1.4.20.1.2.127.0.0.2 +' => { 'Error_Status' => 'No error', 'Total_Time' => '0:00:00.0', 'Last_Time' => '16:29:08.04', '1.3.6.1.2.1.4.20.1.3.127.0.0.2' => [ [ 'ipAdEntNetMask.127.0.0.2', 1 ] ], 'Max_Time_Diff' => '00:00.0', 'Min_Time' => '16:29:08.04', '1.3.6.1.2.1.4.20.1.2.127.0.0.2' => [ [ 'ipAdEntIfIndex.127.0.0.2', 1 ] ], 'Avg_Time' => undef, 'Min_Time_Diff' => '9:59:59.9', 'Max_Time' => '16:29:08.04' }, 'Response -------------- 11.254.49.217:1.3.6.1.2.1.2.2.1.12.20' => {
with this code...
my @key_hash = sort { $key_hash{substr($a,3)} cmp $key_hash{substr($b,3)} } keys %key_hash;
I only need to look at the first three letters.
Any idea what I'm doing wrong?

In reply to Sorting a hash of hashes by Anonymous Monk

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.