You should enter the words (or letters or numbers) on the command line like "perl permnodup.pl a a a b b c". Feel free to change this part of the code:
to do something else. Here is a more versatile version:#Sample use: @ARGV= sort @ARGV; do { print "@ARGV\n"; } while( nextpermute(@ARGV) );
- tye (but my friends call me "Tye")#Sample use: my @elts= @ARGV; my $sep= " "; do { if( ! @ARGV ) { print "What to permute? "; my $line= <STDIN>; chomp( $line ); exit 0 if "" eq $line; if( $line =~ / / ) { $sep= " "; @elts= split " ", $line; } else { $sep= ""; @elts= split //, $line; } } @elts= sort @elts; my $cnt= 0; do { print ++$cnt, ": ", join( $sep, @elts ), "\n"; } while( nextpermute(@elts) ); } while( ! @ARGV ); exit 0;
In reply to (tye)Re3: permute n elements2
by tye
in thread permute n elements2
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |