update: I didn't spot your PERL_UNICODE remark. Ignore the two paragraphs below

If you have a recent perl (5.8.5ish 5.8.1 or higher) I'm pretty sure your original file handles are NOT marked as utf-8, since there is no way they will be set to utf-8 automatically.

Observe: (this is perl 5.8.8 with $LANG=en_US.UTF-8 on an xterm in utf8 mode):

$ perl -e'print "\x{2639}"' Wide character in print at -e line 1. ☹

But yeah, it seems strange that duplicating a filehandle doesn't copy its encoding. On the other hand, if you open() a file without explicitly setting an encoding it defaults to the systems default 8-bit encoding (see perluniintro and perlopentut), so there's something to be said for the current behaviour.

Also, PerlIO::get_layers is (probably) correct. You don't see the utf8 layer because it's not set (see above).

update2: about that get_layers issue: it seems to work correctly for me (taking into account that layers won't be copied):

PERL_UNICODE=SDL perl -e'print PerlIO::get_layers(STDOUT)' unixperlioutf8

In reply to Re: bug? duped filehandles and unicode by Joost
in thread bug? duped filehandles and unicode 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.