Hi !

As you said, your strings seems to be allready in unicode. They seem to be allready sequences of unicode characters and are certainly marked as unicode/utf8 within perl. You can check that with utf8::is_utf8($string) (that should be true in your case).

So there's no point decoding them again within perl.

decode works on sequence of bytes, not on sequence of characters, and here you got a sequence of unicode characters.

I guess what you like to do is print your strings in a UTF-8 terminal. To do so, you simply have to either:

Hope it helps. unicode/utf8 are often quite confusing.

The confusion comes from mixing unicode and utf8 concepts. Unicode is a standard for universal character representation. You can view it as the format of internal strings in perl when an input string needs that kind of characters. So a string of unicode character is a string of characters.

utf8 is a _way_ to encode unicode strings. A utf8 string is a string of bytes, and should be used exclusively for I/O. encode_utf8($string) transforms an internal perl string (unicode or not) into a sequence of utf8 bytes. decode_utf8($string) transforms a sequence of utf8 bytes into a unicode internal perl string.

-- Nice photos of naked perl sources here !


In reply to Re: Decoding UTF-8 - "Cannot decode string with wide characters" by jeteve
in thread Decoding UTF-8 - "Cannot decode string with wide characters" by kiz

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.