papai has asked for the wisdom of the Perl Monks concerning the following question:
What I want to do is have the same table but sorted on the Value column. Therefore I would see 1000 at the top and then 20 next, etc... I read from a delimited file and create a hash of a hash of an array. The array holds the value, a counter, which is incremented within a while loop with the following lineKey1 Key2 Value -------------------------------------- red bike 5 red car 4 red shoes 20 yellow shoes 1 yellow skates 1000
I currently print the table above with the following:while (<>){ ... $hash{key1}{key2}[0]++; ... }
How do I print the table by sorting strictly on the value?for $colour (sort keys %hash){ for $device (sort keys %{ $hash{$colour}}){ printf("\n%-55s %-55s %-40s", $colour, $device, $hash{$colour}{$device}[0] ); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sorting multi-hash values
by holli (Abbot) on Aug 22, 2007 at 17:57 UTC | |
by naikonta (Curate) on Aug 22, 2007 at 18:32 UTC | |
by holli (Abbot) on Aug 22, 2007 at 18:35 UTC | |
by naikonta (Curate) on Aug 22, 2007 at 18:41 UTC | |
by moritz (Cardinal) on Aug 22, 2007 at 20:31 UTC | |
by ikegami (Patriarch) on Aug 22, 2007 at 20:27 UTC | |
|
Re: Sorting multi-hash values
by TGI (Parson) on Aug 22, 2007 at 19:05 UTC | |
|
Re: Sorting multi-hash values
by dwm042 (Priest) on Aug 22, 2007 at 19:13 UTC | |
by papai (Novice) on Aug 24, 2007 at 13:51 UTC | |
|
Re: Sorting multi-hash values
by GrandFather (Saint) on Aug 22, 2007 at 21:09 UTC |