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;

In reply to Re: Split is ignoring locale settings by Anonymous Monk
in thread Split is ignoring locale settings by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.