• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 272
  • Last Modified:

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
0
faithless1
Asked:
faithless1
  • 2
1 Solution
 
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now