in reply to Re^2: Tell whether two strings differ at only one position
in thread Tell whether two strings differ at only one position

Except it doesn't work:
sub compare { (($_[0] ^ $_[1]) =~ tr/\0//c) < 2; } print((compare('abc', 'abcd') ? 'ok' : 'not ok'), "\n");
It should be
sub compare { length $_[0] == length $_[1] && (($_[0] ^ $_[1]) =~ tr/\0//c) < 2; }

Replies are listed 'Best First'.
Re^4: Tell whether two strings differ at only one position
by rg0now (Chaplain) on Aug 05, 2005 at 09:59 UTC
    Thanks ikegami for pointing this one little important fact out to me! I have almost forgot my very own specifications for the problem. That tr///c absolutely made my day...