P is for Practical  
PerlMonks 
RE: How can I improve this?by ferrency (Deacon) 
on Jul 25, 2000 at 07:31 UTC ( #24239=note: print w/ replies, xml )  Need Help?? 
If the only thing about the order of your permutations that matters, is keeping the number of 0's as low as possible for as long as possible, then another way to accomplish your goal would be to create a complete set of permutations in any order, and then sort the set of permutations according to the number of 0's in each. 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: 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. I hope this helps. Goshdarnit they both beat me to it, and with nearly the same answer... :) Alan
In Section
Seekers of Perl Wisdom

