Permute Perl Help

Posted on 2012-08-13
Last Modified: 2012-08-26

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

Question by:faithless1
    LVL 25

    Accepted Solution

    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'
    LVL 25

    Expert Comment

    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} }'

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
    I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now