...but come to think of it, it is simpler to just fix your original version:
...and about 3X faster too:sub append_n { my ( $str, $array ) = @_; my $nstring = "N" x length($str); foreach my $sbstr ( @$array ) { my $ofs = 0; while ( ( my $pos = index $str, $sbstr, $ofs ) > -1 ) { substr ($nstring, $pos, length ($sbstr)) = $sbstr; $ofs = $pos + 1; } } return $nstring; } __END__ GATTACGNNNNGCGCTCGNNNAACGGCA GATTACGAGNNNNNNNCGTGTAANNNNN NNNTACGAGTGGCGCTCGTGNNNNNNNN NNNNNNNNNNGGNNNNNNNNNNNNGGNN
In hindsight this is not surprising, since my (vec-based) solution does everything that yours does plus the unnecessary bit-vector stuff. Doh!Rate bitvec substr bitvec 18618/s -- -74% substr 70275/s 277% --
the lowliest monk
In reply to Re^2: Recovering Substrings to String with Gap
by tlm
in thread Recovering Substrings to String with Gap
by monkfan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |