in reply to Split is ignoring locale settings
Forget about locales. They are from an era before Unicode. Use the other modern tools Perl and CPAN give you.
That being said, your problem is that you simply do not operate on a Perl string, but a buffer of bytes. When you split that, you get bytes. However, you want to split a string into characters.
The difference is in the need of decoding your input from bytes to characters. Learn about the whole topic of encoding at p3rl.org/UNI.
Sample solution:
use Encode qw(decode);
my $bytes = "Chrt pln skvrn vtrhl skrz trs chrp v \xC4\x8Dtvr\xC5\xA5 Kr\xC4\x8D."
my $text = decode 'UTF-8', $bytes;
# alternatively:
# use utf8;
# my $text = 'Chrt pln skvrn vtrhl skrz trs chrp v čtvrť Krč.';
my @characters = split //, $text;
# (
# 'C', 'h', 'r', 't', ' ', 'p', 'l', 'n', ' ', 's', 'k', 'v', 'r', 'n',
# ' ', 'v', 't', 'r', 'h', 'l', ' ', 's', 'k', 'r', 'z', ' ', 't', 'r',
# 's', ' ', 'c', 'h', 'r', 'p', ' ', 'v', ' ', "\x{10d}", 't', 'v', 'r',
# "\x{165}", ' ', 'K', 'r', "\x{10d}", '.'
# )
Since everything is UTF-8, it's a bit difficult for you as a beginner to grok what's going on. Exchange the following two lines, perhaps it will enlighten you quickly.
my $bytes = "Chrt pln skvrn vtrhl skrz trs chrp v \xe8tvr\xbb Kr\xe8.";
my $text = decode 'Latin-2', $bytes;
|
|---|