Perl: the Markov chain saw PerlMonks

### Comment on

 Need Help??

Hi Perl Monks,

I am a beginner in perl programming. I am interested in generating all possible combinations of 2-letter & 3-letter words from a set of four letters (A,T,G,C), choosing one letter at a time for each position. I searched for perl scripts in CPAN and other online sources but I didn't get the codes. But a few scripts are indeed available for permutations and combinations. If the size of the word is small, it's easy to do it manually but when the size of the word is 10 or more it is time-consuming to generate all the combinations. If any perl code is available, it will be very useful to the biologists. If 'n' is the size of the word, then 4**n (i.e. 4 to the power word size) combinations are possible unlike possible permutations and combinations. For 2-letter words, there will be 16 combinations as given below (unlike 12 permutations and 6 combinations) and for 3-letter words 64 combinations are possible in the same way (unlike fewer permutations and combinations). May I request perl monks to suggest me some reference reading material or codes for this purpose?

```#!/usr/bin/perl
use warnings;
use strict;
## Perl script to create all possible combinations of A,T,G & C
# of varying lengths:
print"\n This program will generate all possible combinations of A,T,G
+ & C:";
print"\n Enter the length of words you want (say 2 or 3 etc.): ";
my \$num=<STDIN>;my \$four=4;
chomp \$num;
my \$no_combi=\$four**\$num;
print"\n Total Number of Combinations= \$no_combi\n";
my \$combi_2l=". . .????";
my \$combi_3l=". . .????";
print"\n All possible combinations of 2-letter words: ???\$combi_2l\n";
print"\n All possible combinations of 3-letter words: ???\$combi_3l\n";
exit;

The expected results will look like:

```All possible combinations of 2-letter words (16):
AA
AT
AG
AC
TA
TT
TG
TC
GA
GT
GG
GC
CA
CT
CG
CC

For 3-letter words, there will be 64 combinations like:

```All possible combinations of 3-letter words:
AAA
...
...
...
CCC

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

• Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
• Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
• Read Where should I post X? if you're not absolutely sure you're posting in the right place.
• Posts may use any of the Perl Monks Approved HTML tags:
a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
• You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
 For: Use: & & < < > > [ [ ] ]
• Link using PerlMonks shortcuts! What shortcuts can I use for linking?

Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2018-03-20 08:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
When I think of a mole I think of:

Results (248 votes). Check out past polls.

Notices?