in reply to More efficient way for this pattern match?
No, the split function is not a good way to do this trick. A regular expression is a better bet:
#!/usr/bin/perl use strict; use warnings; use File::Copy; my $str1='MCCAALAPPMAATVGPESIWLWIGTIGMTLGTLYFVGRGRGVRDRKMQEFYIITIFITTI +AAAMYFAMATGFGVT-------------EVMVG----DE---ALTIYWARYADWLFTTPLLLLDLSLLA +GANRN----TIATLIG-LDVFMIG---T---GAIAALSST-PGTRIAWWAIST--GALL--ALLYVLVG +TLSENARNRAPEVA--SLFGRLRNLVIALWFLYPVVWILGT---EGTFGILP--LYWETAAFMVLDLSA +KVGFGVILLQSRSVLERVATPTAAPT'; my $str2='--OOOOOOOOOOOOOOOOMMMMMMMMMMMMMMMMMMMMMIIIIIIIIIIMMMMMMMMMMM +MMMMMMMMMMOOOOO-------------OOOOO----OO---OOOOMMMMMMMMMMMMMMMMMMMMMII +IIIII----MMMMMMM-MMMMMMM---M---MMMMMMOOO-OOOOMMMMMMMM--MMMM--MMMMMMMM +MMIIIIIIIIIIII--IIIIMMMMMMMMMMMMMMMMMMMMO---OOO-OOOO--OOOMMMMMMMMMMMM +MMMMMMMMMIIIIIIIIIIIII----'; while ($str2 =~ /(-+)/g) { my ($start, $end) = ($-[0], $+[0]); my $matchLen = $end - $start; next if substr($str1, $start, $matchLen) =~ /^-+$/; my $chIdx = $end == length($str2) ? $start - 1 : $end; substr ($str2, $start, $matchLen, substr($str2, $chIdx, 1) x $matc +hLen); } print $str2;
Prints:
OOOOOOOOOOOOOOOOOOMMMMMMMMMMMMMMMMMMMMMIIIIIIIIIIMMMMMMMMMMMMMMMMMMMMM +OOOOO-------------OOOOO----OO---OOOOMMMMMMMMMMMMMMMMMMMMMIIIIIII----M +MMMMMM-MMMMMMM---M---MMMMMMOOO-OOOOMMMMMMMM--MMMM--MMMMMMMMMMIIIIIIII +IIII--IIIIMMMMMMMMMMMMMMMMMMMMO---OOOOOOOO--OOOMMMMMMMMMMMMMMMMMMMMMI +IIIIIIIIIIIIIIII
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: More efficient way for this pattern match?
by ikegami (Patriarch) on Apr 14, 2015 at 03:00 UTC | |
|
Re^2: More efficient way for this pattern match?
by hdb (Monsignor) on Apr 14, 2015 at 12:08 UTC | |
by GrandFather (Saint) on Apr 14, 2015 at 21:08 UTC | |
|
Re^2: More efficient way for this pattern match?
by Anonymous Monk on Apr 14, 2015 at 07:14 UTC | |
|
Re^2: More efficient way for this pattern match?
by Anonymous Monk on Apr 14, 2015 at 06:46 UTC |