What's wrong with my code below ?
You appear to be trying to use what I think of as a "meta-for loop" to get the effect of $l nested for loops. No programming language I know of implements this directly.
for ( my $i = 0 ; $i < $l ; $i++ ) { foreach my $nucl (@nucleotides) { substr( $cand_motif, $i, 1 ) = $nucl; push @enumerated_motifs, $cand_motif; #print "$cand_motif\n"; } }
In a language that implemented the "meta-for" construct you could write something like
meta_for ( my $i = 0 ; $i < $l ; $i++ ) { foreach my $nucl (@nucleotides) { substr( $cand_motif, $i, 1 ) = $nucl; } # meta_for push @enumerated_motifs, $cand_motif; #print "$cand_motif\n"; meta_end_for ( my $i = 0 ; $i < $l ; $i++ ) { } # foreach } # meta_end_for
Of course, parsing the above code as written presents serious difficulties. Probably a different syntax would be required.

Update: Probably the best way to implement this (Update2: i.e. the "meta-for" construct) in Perl would be to use eval.

my $code = "xyzzy"; for ( my $i = 0 ; $i < $l ; $i++ ) { $code =~ s/xyzzy/ foreach my \$nucl (\@nucleotides) { substr( \$cand_motif, $i, 1 ) = \$nucl; xyzzy } /; } $code =~ s/xyzzy/ push \@enumerated_motifs, \$cand_motif; #print "\$cand_motif\\n"; /; eval $code;

In reply to Re: Trying to construct all possible strings from 4 bases [ATCG] by jdalbec
in thread Trying to construct all possible strings from 4 bases [ATCG] by monkfan

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.