This said, I find the final computation quite elegant and istructive - I wouldn't have thought of XORing letters even in 100 years.
I had the same reaction as yours when I first encountered the "infamous xor trick" (in this case to find the first position at which two strings differ, or equivalently, the length of the longest common prefix):
Way cool, though it works as written only if the characters are 1 byte long.$a = "foobar"; $b = "foobAr"; ($a ^ $b) =~ /^(\0*)/ and print length $1; __END__ 4
There's always to learn, luckly, provided I'll be able to remember it when I'll need :)
Yep, that's the rub.
the lowliest monk
In reply to Re^3: Substring Distance Problem
by tlm
in thread Measuring Substrings Problem
by monkfan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |