Permute Perl Help

Hello,

The following command produces permutations:
perl -MAlgorithm::Permute -lane ' Algorithm::Permute::permute { print "@F" } @F'

i.e. (input)
test1 test2
test3 test4

i.e. (ouput)
test1 test2
test2 test1
test3 test4
test4 test3

This does not produce all variants. Is there a way to adjust the script so it will produce all variants?

output i'm looking for:

test1 test2
test2 test1
test3 test1
test3 test2
test1 test3
test2 test3

etc
faithless1Asked:
Who is Participating?
 
lwadwellCommented:
The command as is treats each line in the file as the words to be permuted ... and iterates over each line.  Simple solution is to join the lines together.

If you want to permute the entire file as one list, you could do:

perl -MAlgorithm::Permute -lane 'push(@X,@F);END{ Algorithm::Permute::permute { print "@X" } @X'
0
 
lwadwellCommented:
As you only want permutations of only 2 values

perl -MAlgorithm::Permute -lane 'push(@{$X},@F);END{ $p= new Algorithm::Permute($X,2);while(@w=$p->next){print @w} }'
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.