Do a Schwartzian Transform to capture the color code and a boolean to indicate whether there is a count, then sort, and finally unpack and print.
#!/usr/bin/perl -w use strict; print map {$_->[2]} sort {$b->[1] <=> $a->[1] || $a->[0] <=> $b->[0]} map {/(\d+).*?(\d+)/ ? [$1, !!$2, $_] : ()} <DATA>; 1; __DATA__ Colour Quantity 70 (Grey brown mix) 3 72 (Green mix) 10 74 (Fuschia mix) 8 76 (Mauve mix) 11 77 (Blue mix) 6 90 (Beige pink mix) 12 91 (Peach cream mix) 8 92 (Silver cream mix) 10 93 (Beige blue mix) 9 78 (Black white mix) 0 75 (Red mix) 0 73 (Aqua mix) 0 71 (Beige mix) 0
Outputs
70 (Grey brown mix) 3 72 (Green mix) 10 74 (Fuschia mix) 8 76 (Mauve mix) 11 77 (Blue mix) 6 90 (Beige pink mix) 12 91 (Peach cream mix) 8 92 (Silver cream mix) 10 93 (Beige blue mix) 9 71 (Beige mix) 0 73 (Aqua mix) 0 75 (Red mix) 0 78 (Black white mix) 0

Update: L~R pointed out that I did not use the initial data structure that you described, and therefore my result wasn't as helpful. Unfortunately, you do not state what actually are the keys of the third level hash. Assuming they are the colour codes and the names are inside the hash with Qua, then the following would work:

#!/usr/bin/perl -w use strict; my %products; $products{Cat}{Pro} = { 70 => {Name => 'Grey brown mix', Qua => 3}, 72 => {Name => 'Green mix', Qua => 10}, 74 => {Name => 'Fuschia mix', Qua => 8}, 76 => {Name => 'Mauve mix', Qua => 11}, 77 => {Name => 'Blue mix', Qua => 6}, 90 => {Name => 'Beige pink mix', Qua => 12}, 91 => {Name => 'Peach cream mix', Qua => 8}, 92 => {Name => 'Silver cream mix', Qua => 10}, 93 => {Name => 'Beige blue mix', Qua => 9}, 78 => {Name => 'Black white mix', Qua => 0}, 75 => {Name => 'Red mix', Qua => 0}, 73 => {Name => 'Aqua mix', Qua => 0}, 71 => {Name => 'Beige mix', Qua => 0}, }; foreach my $colour ( sort {!!$products{Cat}{Pro}{$b}{Qua} <=> !!$products{Cat}{Pro}{$a} +{Qua} || $a <=> $b} keys %{$products{Cat}{Pro}} ) { printf "%-2s %-22s %s\n", $colour, "($products{Cat}{Pro}{$colour}{ +Name})", $products{Cat}{Pro}{$colour}{Qua}; } 1; __END__
- Miller

In reply to Re: Complex conditional sort by wind
in thread Complex conditional sort by Zhris

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.