Unless you need some of those variables later, we could eliminate some clutter.

use strict; use warnings; #generate all posibilites of a DNA sequence my @Bases = qw(A C G T); my $SequenceMinLength = 1; my $SequenceMaxLength = 3; print 'Number of Sequence lengths to permute is ', $SequenceMaxLength - $SequenceMinLength + 1, "\n"; my @allSequence; foreach my $currLength ($SequenceMinLength .. $SequenceMaxLength){ push @allSequence, Ordered_Combinations($currLength, @Bases); } #Prints sequences to screen # - Too many entries after length of sequence is greater than 4. my $i; foreach my $finalsequence (@allSequence){ ++$i % @Bases ? print "$finalsequence\t" : print "$finalsequence\n +"; }

By using @Bases instead of 4, we get @Base columns, aiding readability.

sub Ordered_Combinations { my $n = shift; --$n ? map { my $d = $_; map "$d$_", Ordered_Combinations($n,@_) } @_ : @_ }
HTH,
Charles K. Clarkson

In reply to Re: Re: Generate all possibilities by CharlesClarkson
in thread Generate all possibilities by lostcause

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.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, 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, summary, 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.