I believe this is very close but the problem now is my new hash, "$value_hash", can only hold one unique key. Therefore if I have list of values like:
colour device value ---------------------- red bike 1000 red shoes 1000 blue car 4 black plane 6 blue boat 1000 pink shoes 5 red car 5
The $value_hash will only have the following list:
colour device value ------------------------ blue boat 1000 black plane 6 red car 5 blue car 4
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):
foreach my $colour ( keys %hash) { foreach my $device ( keys %{$hash{$colour}}) { my $val = $hash{$colour}{$device}[0]; $value_hash{$val}{$colour}{$device}[0]++; } }
After that I then print the key (value) in order:
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); } } }
Which now produces table...
colour device value ---------------------- red bike 1000 red shoes 1000 blue boat 1000 black plane 6 pink shoes 5 red car 5 blue car 4
Thank you for pointing me in the right direction monks...Papai

In reply to Re^2: Sorting multi-hash values by papai
in thread Sorting multi-hash values by papai

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.