in reply to Re: More efficient way for this pattern match?
in thread More efficient way for this pattern match?

Your script seems to make some additional assumptions that I cannot find in the original question. For example, for

my $str1='--M--CCA'; my $str2='-----OOO';

your script prints OOOOOOOO while I would have thought it should be --O--OOO?

UPDATE: In order to avoid any confusion, the strings above are NOT part of the original question but examples I constructed assuming they could occur. The purpose of this was to highlight a situation where the proposed script would deliver something that violates the original requirements. Not sure the example is really relevant.

Replies are listed 'Best First'.
Re^3: More efficient way for this pattern match?
by GrandFather (Saint) on Apr 14, 2015 at 21:08 UTC

    Good catch. It's a bug. The line:

    next if substr($str1, $start, $matchLen) =~ /^-+$/;

    should be more like (untested):

    next if ! matchLen || substr($str1, $start, $matchLen) !~ /[^-]/;
    Perl is the programming world's equivalent of English