For example (using @a...@e):
If you want more order than just "least number of zeros first," then you can create a more complex sorting routine using an || operator to break the tie between equal numbers of zeros. For example, to sort first according to number of zeros, and then asciibetical on the permutation created, use this:for my $a (0..@a) { for my $b (0..@b) { for my $c (0..@c) { for my $d (0..@d) { for my $e (0..@e) { # Build a hash with the permutation as the key, and the # number of zeros as the value $permutation{$a[$a].$b[$b].$c[$c].$d[$d].$e[$e]} = !$a + !$b + !$c + !$d + !$e; }}}}} # Now sort according to the number of zeros return sort {$permutation{$a} <=> $permutation{$b}} keys %permutation;
This code doesn't treat @c any differently than the rest of the arrays. If you don't care about @c, you could simply leave it out of the "number of zeros" calculation when assigning things into %permutation.return sort {$permutation{$a} <=> $permutation{$b} || $a cmp $b} keys %permutation;
I hope this helps.
Goshdarnit they both beat me to it, and with nearly the same answer... :)
Alan
In reply to RE: How can I improve this?
by ferrency
in thread How can I improve this?
by Dogg
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |