|
|
| Pathologically Eclectic Rubbish Lister | |
| PerlMonks |
Re: Is it possible to find the number of matching and non-matching positions in strings using perl code?by moritz (Cardinal) |
| on May 11, 2012 at 06:46 UTC ( #969913=note: print w/ replies, xml ) | Need Help?? |
|
Finding characters where two string differs can be done with bitwise operations. If you binary XOR two strings, positions where both characters are the same come out as a null byte. When doing several comparisons, one can accumulate the differing positions using binary OR:
This approach should scale well for longer strings, since the binary operations are faster than looping over all characters.
In Section
Seekers of Perl Wisdom
|
|