Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
The hash: keys 50:20:6:4, topic 1, and 5 index with its totals and so on$bighash{$key1}{$key2}{$key3}{$key4}[$topic-1][$index-1] = $total;
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' -> | ...................| ....................'30', ....................'40', ....................'20', ....................'20', ....................'10' ....................|, ....................| ....................'28', ....................'10', ....................'76', ....................'20', ....................'10' ....................|, ........{'60' => { ..........'30' => { ............'6' => { ...............'4' => | | ....................'30',
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.$VAR1 = {'50' => { ...........'20' => { ............'6' => { .............'4' => | .....................| ....................'40',=>index2 ....................'30',=>index1 ....................'20',=>index3 ....................'20',=>index4 ....................'10'=>index5 .....................|,
How do I sort those values without affecting the whole hash structure?, and is it my hash structure? OK?
Thanksedited by ybiC: balanced <code> tags around output examples
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: sorting an array of hashes by the value of the keys
by dragonchild (Archbishop) on Aug 12, 2003 at 14:09 UTC | |
|
Re: sorting an array of hashes by the value of the keys
by sgifford (Prior) on Aug 12, 2003 at 18:40 UTC | |
|
Re: sorting an array of hashes by the value of the keys
by sweetblood (Prior) on Aug 12, 2003 at 14:13 UTC | |
by cfreak (Chaplain) on Aug 12, 2003 at 15:11 UTC | |
by sauoq (Abbot) on Aug 12, 2003 at 17:20 UTC |