in reply to Re^2: Hamming Distance Between 2 Strings - Fast(est) Way?
in thread Hamming Distance Between 2 Strings - Fast(est) Way?
I'm not sure that $k, $l are any more meaningful than $_[0], $_[1] and you pay a small performance penalty for obtaining those names.
Does $diff really capture what it is naming? I've used $xor or $mask for that in the past, but I wonder if it isn't best left unnamed.
I don't see any purpose in naming the return value, just to return it. Better to say return <EXPR>; and give the function a proper name like hammingDistance() and allow it to name the return value.
While using tr/\0//c produces the same result as length - tr/\0/\0/, the major difference is that the former modifies the string being inspected, deleting the chars counted, where the latter does not. It just counts.
On the short strings in the OP this is insignificant. But the technique works for any length strings, and as DNA strings can get very large indeed, the difference then becomes very significant.
Overall, I prefer my version to yours, but each to their preference :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Hamming Distance Between 2 Strings - Fast(est) Way?
by Roy Johnson (Monsignor) on Oct 14, 2005 at 19:12 UTC | |
by BrowserUk (Patriarch) on Oct 14, 2005 at 21:04 UTC |