You still seem to have a bug occasionally. You report an offset of 75, but I make it to be 59?

#! perl -slw use strict; sub slidingMatch { my ($seq, $word) = @_; return "Complete match at $-[1]\n" if $seq =~ /($word)/; my @bestMatch; # Try matching start my $str = substr $seq, 0, 3; my $wordLen = length $word; while ($word =~ /$str/g) { my $tailLen = length ($word) - (my $start = $-[0]); my $subWord = substr ($word, $wordLen - $tailLen); next if $seq !~ m/^$subWord/; @bestMatch = ($start, $tailLen); last; } # Try matching end my $rword = reverse $word; my $rseq = reverse $seq; $str = substr $rseq, 0, 3; while ($rword =~ /$str/g) { my $tailLen = length ($rword) - (my $start = $-[0]); last if @bestMatch && $tailLen < $bestMatch[1]; my $subWord = substr ($rword, $wordLen - $tailLen); next if $rseq !~ m/^$subWord/; @bestMatch = (length ($seq) - $start, $tailLen); last; } return "Partial match found at $bestMatch[0] for $bestMatch[1] cha +racters\n" if @bestMatch; return "No match found for $word in $seq\n"; } print slidingMatch #012345678 012345678 012345678 012345678 012345678 012345678 'GAATGTTTTAGCAATCTCTTTCTGTCATGAATCCATGGCAGTGACCATACTAATGGTGACTGCCATTGA +TGGAGGGAGACACA', 'CTGCCATTGA +TGGAGGGAGACACAACGTACGT'; __END__ c:\test>junk Partial match found at 75 for 24 characters

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^2: Searching for a word that may only exist in part by BrowserUk
in thread Searching for a word that may only exist in part by seaver

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.