This permutation generator generates only unique permutations, even when the list to be permuted contains duplicates. It can be used for huge lists since the list of permutations is not built in memory (and we don't have to keep any "context" info around). To use it, first sort the array, then each call to nextPermute() will permute the array in place, returning false when all permutations have been done (which also means that the array was just in reverse sorted order and has been left that way).
Note that the permutations get generated in "sorted order". For example, if all of the items are gt " ", then the output of the sample usage would already be sorted.
The call to reverse was originally a call to sort. When I noticed this inefficiency, I compared the improved version against Algorith::Permute and all of the permutation finders that it included in its benchmark. My (improved) code was faster than all of them except Algorith::Permute's [ which are written in XS, so being only about 1/2 as fast was quite acceptable to me (: ]. Note also that the version below handles duplicates while none of the other fine algorithms did.
Update: Did s/nextpermute/nextPermute/.
Update: Now available as part of Algorithm::Loops.
Update: Replaced 'while' with 'until' as the comparisons where "backward" (implied negations).