Outputs#!/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
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:
- Miller#!/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__
In reply to Re: Complex conditional sort
by wind
in thread Complex conditional sort
by Zhris
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |