in reply to Uniquely sorting arrays

Abstract answer: find all the permutations of the array indices, store each permutation as an arrayref, and then do this:

# @array = (list, of, items); foreach my $perm (@index_permutation) { my @indices = @$perm; foreach (@index) { # do something with @array[$_]; } }

For finding the permutations, take a gander at permutations? and attendant thread. You could save on storing the index permutations by encasing the inner loop in the loop that finds the permutations, I suppose.

If you go my way and work on any sizeable array, I wouldn't want to be your sysadmin who gets a page when the memory gets critically low, though =)

Philosophy can be made out of anything. Or less -- Jerry A. Fodor