The problem is that you add an encoding step without a decoding step. When you don't add the utf8 layer, then the literal string Çirçös\n" is interpreted as a series of bytes, and written to STDOUT as such. No problem.

When you add the output layer, you tell print to convert from characters to bytes. So the Ç is interpreted as a series of characters, and defaults to Latin-1 encoding. Its UTF-8 bytes are 0xc3 0x87, and that is interpreted as U+00C3 LATIN CAPITAL LETTER A WITH TILDE, U+0087 <control>, so what you'll see for the first character is Ã&#135;

This can be solved by also adding the line use utf8; to your program, telling it that string literals should be decoded as utf-8.

I tried to describe Perl's Unicode model in this article, I hope it will help you understanding what's going on.


In reply to Re: clarification on binmode STDOUT by moritz
in thread clarification on binmode STDOUT by rmflow

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.