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:
#Sample use:
@ARGV= sort @ARGV;
do {
print "@ARGV\n";
} while( nextpermute(@ARGV) );
to do something else. Here is a more versatile version:
#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;
-
tye
(but my friends call me "Tye") |