It should besub compare { (($_[0] ^ $_[1]) =~ tr/\0//c) < 2; } print((compare('abc', 'abcd') ? 'ok' : 'not ok'), "\n");
sub compare { length $_[0] == length $_[1] && (($_[0] ^ $_[1]) =~ tr/\0//c) < 2; }
In reply to Re^3: Tell whether two strings differ at only one position
by ikegami
in thread Tell whether two strings differ at only one position
by rg0now
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |