I thought the capturing parenthesis would capture the look-behind pattern as well.

It does — except I wouldn't think of what was captured as "the look-behind pattern", but simply as "the pattern" or maybe "the match." Look-around doesn't really enter in to it, and I don't see any need to bring in substr either; you already seem to have everything you need in $1, e.g. (with one repeated sequence):

c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my $line = 'AAAATTTTCCCCGGGGAAAGGxAAAACCCCTTTTGGGGAAAGGxAAAATTTTCCCCGGGGAAAGG' ; ;; my (%unique_data, $count); while ($line =~ m{ (.{9} [ATCG]{10} GG) }xmsg) { print qq{>crispr_@{[ ++$count ]} '$1'} unless $unique_data{$1}++; } ;; dd \%unique_data; " >crispr_1 'AAAATTTTCCCCGGGGAAAGG' >crispr_2 'AAAACCCCTTTTGGGGAAAGG' { "AAAACCCCTTTTGGGGAAAGG" => 1, "AAAATTTTCCCCGGGGAAAGG" => 2 }

However, I think the line-by-line processing of your code here is problematic. In the OPed code, the function  loadSequence() (supposedly) concatenates all lines of  ATCG bases in a file together before trying to extract sub-sequences of interest. In line-by-line processing, a sub-sequence may be interrupted by a newline and thus be missed.

(OTOH, the whole 21-base-versus-12-base aspect of the OPed code leaves me puzzled; I can't quite figure out what the OPer was going for there.)


Give a man a fish:  <%-{-{-{-<


In reply to Re^4: unique sequences by AnomalousMonk
in thread unique sequences by Anonymous Monk

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.