in reply to Re: Complex conditional sort
in thread Complex conditional sort

ikegami,
Perhaps I am missing something, but I don't see how this solves the problem. The colors must be sorted alphabetically in two groups. The first group should be those with quantities above 0 and the second group should be 0. As you have described it, they will be ordered first by quantity (correctly putting all colors with quantities in front of those without) but within the groups you will have the wrong alphabetical order.

Cheers - L~R

Replies are listed 'Best First'.
Re^3: Complex conditional sort
by ikegami (Patriarch) on Mar 09, 2011 at 00:37 UTC

    Oops, I thought he wanted to group by quantity. To group by presence/absence (presence first), it's simplest to solidify the concept into values that can be compared with <=> or cmp. Let's pick zero for presence and one for absence (since zero comes before one).

    my $pro_products = $products{Cat}{Pro}; sort { $pro_products->{$a}{Qua} ?0:1 <=> $pro_products->{$b}{Qua} ?0:1 || $a cmp $b } keys %$pro_products

    Update: Down below, L~R picked "A" and "B" instead of 0 and 1. Same idea.