in reply to (tye)Re2: permute n elements2
in thread permute n elements2

you were right. however, I copied the text from permuting w/dup...and saved it with , .pl when i ran it from the command prompt it just gave me another command prompt. I had no chance to input any data. oh yeah, can it permute numbers too? my command prompt looks like as follows: perl permnodup.pl then i hit enter. Even if i doubleclick on the icon permnodup.pl the perl msdos window comes on and goes off, instead of waiting for my permutation. What am i doing wrong? I await your enlightenment!!!!!!

Replies are listed 'Best First'.
(tye)Re3: permute n elements2
by tye (Sage) on Oct 29, 2000 at 11:42 UTC

    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")