I have my hash with the following structure - not sure it is the good one, considering I want $topic, and $index be also keys -
$bighash{$key1}{$key2}{$key3}{$key4}[$topic-1][$index-1] = $total;
The hash: keys 50:20:6:4, topic 1, and 5 index with its totals and so on
$VAR1 = {'50' -> { ..........'20' -> { .............'6' -> { ...............'4' -> | ...................| ....................'30', ....................'40', ....................'20', ....................'20', ....................'10' ....................|, ....................| ....................'28', ....................'10', ....................'76', ....................'20', ....................'10' ....................|, ........{'60' => { ..........'30' => { ............'6' => { ...............'4' => | | ....................'30',
For each set of keys in specific $topic I have a set of index: index1, index2, index3...indexN and its total I want to sort the $index by the value of its $total, without affecting the order of the $keys and $topic and return...
$VAR1 = {'50' => { ...........'20' => { ............'6' => { .............'4' => | .....................| ....................'40',=>index2 ....................'30',=>index1 ....................'20',=>index3 ....................'20',=>index4 ....................'10'=>index5 .....................|,
I wrote the word "index.." besides each total as an example, because I need to keep track of which index was, as another key. So maybe my initial hash structure was not ok.

How do I sort those values without affecting the whole hash structure?, and is it my hash structure? OK?

Thanks

edited by ybiC: balanced <code> tags around output examples


In reply to sorting an array of hashes by the value of the keys 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.