Beware that binary comparison of strings does not work on Unicode. Even length() doesn't work. Well, it depends what type of comparison you want.
If you want to compare if the strings are exactly the same bit-by-bit, your stuff works. If you need to compare if the characters are functionally equivalent, that's a different matter.
As discussed before, many Unicode characters can be encoded in more than one way, see Re^2: incorrect length of strings with diphthongs
Further, even if you have one character that's exactly the same Unicode character in both strings, they still might be displayed completely different. Aside from the Umlaut stuff, you have other modifiers as well, like skin tone for Emoji, right-to-left stuff. And also there some scripts like Arab where the display of a character changes depending on the characters around it.
And what's extra nice about about modifier characters is that it may or may not modify your debug prints:
my $modifier = chr(0x200F);
print "The character $modifier is only in string 1\n";
|