I have the following hash:

$data{$meas_name}{$suffix_name}{$corner}{'value'}

Example:

$data{'meas_1'}{'suffix_1'}{'C1'}{'value'} = 10.2 $data{'meas_1'}{'suffix_2'}{'C1'}{'value'} = 4.7 $data{'meas_1'}{'suffix_3'}{'C1'}{'value'} = 5.2 $data{'meas_1'}{'suffix_4'}{'C1'}{'value'} = 11.8 $data{'meas_1'}{'suffix_5'}{'C1'}{'value'} = 0.7

There will be multiple values for the $meas_name field, multiple suffixes for each meas name, and multiple corners. Each corner will have the same number of suffixes for a given meas name. From the above, I would like to create a new hash of arrays with the following structure:

$ordered_hash{$meas_name}{$corner_name} = ("suffix_4", "suffix_1", "su +ffix_3", "suffix_2", "suffix_5")

That is, for each value of meas and corner, the new hash of arrays contains an ordered list of suffixes that correspond to the values in the {'value'} field sorted from smallest to largest. I know how to solve this problem if the original hash was created as $data{$meas_name}{$corner}{$suffix_name}{'value'} rather than $data{$meas_name}{$suffix_name}{$corner}{'value'} - I could simply use 3 foreach loops and a sort command to sort the original hash by the {'value'} field. The problem is that I need the hash to be ordered as it has been created above because I need to print it out in that order at the very end of my script.


In reply to need help sorting a multilevel hash by a particular key by Special_K

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.