The output does not contain words like "at" but this might not be a problem if you do the pattern matching accordingly.sub nextPermute(\@) { my( $vals )= @_; my $last= $#{$vals}; return "" if $last < 1; # Find last item not in reverse-sorted order: my $i= $last-1; $i-- while 0 <= $i && $vals->[$i] ge $vals->[$i+1]; # If complete reverse sort, we are done! return "" if -1 == $i; # Re-sort the reversely-sorted tail of the list: @{$vals}[$i+1..$last]= reverse @{$vals}[$i+1..$last] if $vals->[$i+1] gt $vals->[$last]; # Find next item that will make us "greater": my $j= $i+1; $j++ while $vals->[$i] ge $vals->[$j]; # Swap: @{$vals}[$i,$j]= @{$vals}[$j,$i]; return 1; } @A= sort qw[a r t]; do { print @A, "\n"; } while( nextPermute(@A) ); __OUTPUT__ art atr rat rta tar tra
In reply to Re: Finding words within a character set
by pelagic
in thread Finding words within a character set
by ruhk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |