in reply to Sorting multi-hash values
For interest. May not be suitable in production code. ;)
use strict; use warnings; my %hash; my $counter; while (<DATA>) { chomp; my ($key1, $key2) = split; $hash{$key1}{$key2}[0] = ++$counter; } printf "%-12s%-12s%-12s\n", @{$_}[1, 2, 0] for ['Value', 'Key1', 'Key2 +'], ['-' x 12, '-' x 12, '-' x 12], sort {$b->[0] <=> $a->[0]} map {[$hash{$_->[0]}{$_->[1]}[0], @$_]} map {my $key = $_; map {[$key, $_]} keys %{$hash{$_}}} keys %hash; __DATA__ red bike red car red shoes yellow shoes yellow skates
Prints:
Key1 Key2 Value ------------------------------------ yellow skates 5 yellow shoes 4 red shoes 3 red car 2 red bike 1
|
|---|