in reply to Re: Detecting transpositions
in thread Detecting transpositions
So here it is with bonus, just a little longer... And now, its just a little faster than yours. Except on large identical strings where it is 3 times faster because of the first line. Without it the regexp would perform very slow.
T I M T O W T D I
sub comp { return -1 if $_[0] eq $_[1]; local $_ = $_[0] ^ $_[1]; /^([\x00]*)([^\x00])\2[\x00]*$/; $1 ? length$1 : -1; }
T I M T O W T D I
|
---|
In Section
Seekers of Perl Wisdom