|
|
| more useful options | |
| PerlMonks |
Re: How can I count the number of substitutions of one letter in a string by another letter in the other string?by Eliya (Priest) |
| on May 11, 2012 at 21:10 UTC ( #970102=note: print w/ replies, xml ) | Need Help?? |
|
In case performance matters and your sequences are longer, you could also use XOR bit logic in combination with tr///:
The idea here is that XORing two strings produces a different value X for each combination of characters, which you can then count with a simple tr/X/X/. The additional prior transformation tr/ATCG/HRDZ/ on one of the strings is required because the XOR operation would otherwise produce symmetric/undirected results, i.e. A2G would be indistinguishable from G2A, etc. (Just in case it isn't clear: the %cnt hash doesn't hold the count results, but rather the subs doing the respective tr/X/X/ counting.)
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||