The $value_hash will only have the following list:colour device value ---------------------- red bike 1000 red shoes 1000 blue car 4 black plane 6 blue boat 1000 pink shoes 5 red car 5
A hashes' keys must be unique, otherwise they get over written with the most recent entry. To prevent losing data, incase I have count values which are duplicates, I recreate a new hash with 3 keys and a value. The keys are "value", "colour", and "device". Creating New Hash "value_hash" (2nd hash):colour device value ------------------------ blue boat 1000 black plane 6 red car 5 blue car 4
After that I then print the key (value) in order:foreach my $colour ( keys %hash) { foreach my $device ( keys %{$hash{$colour}}) { my $val = $hash{$colour}{$device}[0]; $value_hash{$val}{$colour}{$device}[0]++; } }
Which now produces table...for my $value (sort {$b <=> $a} keys %value_hash) { for my $colour ( keys %{$value_hash{$value}}) { for my $os ( keys %{$value_hash {$value}{$colour}}) { printf("\n%-55s %-50s %-10s", $colour, $os, $value); } } }
Thank you for pointing me in the right direction monks...Papaicolour device value ---------------------- red bike 1000 red shoes 1000 blue boat 1000 black plane 6 pink shoes 5 red car 5 blue car 4
In reply to Re^2: Sorting multi-hash values
by papai
in thread Sorting multi-hash values
by papai
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |