>perl -MEncode -e"print encode 'UTF-8', qq{use utf8; my \$x='a\xE1axBy +'; \$x =~ /(.*?)x(A*)y/; }" | perl Malformed UTF-8 character (unexpected continuation byte 0xa1, with no +preceding start byte) in pattern match (m//) at - line 1.

huh? That's not right.

Other tools show that the following is produced.

61 C3 A1 61 78 42 79

C3 is indeed the valid start of a two-byte sequence, A1 is indeed a continuation byte, and C3 A1 is indeed the encoding of LATIN SMALL LETTER A WITH ACUTE (U+00E1). It's a bug.

I believe it's a known bug. It might be fixed in 5.12. You can work around it by putting the following at the start of the pattern:

(?!)\x{2660}|
I don't know if there is a better workaround

I need the two "use"-s, because otherwise I wasn't able to print out something like "αινσ" to terminal.

What you want is

use utf8; use open ':std', ':locale';
or
use utf8; use open ':std', ':encoding(cp852)';

Unforunatley, the first doesn't work on Windows :(


In reply to Re: UTF-8 problem (malformed...) by ikegami
in thread UTF-8 problem (malformed...) by adamvagyok

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.