Your test script perfectly demonstrates that there is nothing different in this case about the actual STDOUT and STDERR filehandles. The difference lies in the functions used to send them the output. print just prints, but warn does a lot more besides: appends line numbers, substitutes a default phrase if none given and can be overridden by SIG{__WARN__}

We can guess therefore that it is something else which warn is doing behind the scenes to set its encoding to utf-8 and thus avoiding the warning. This is the same conclusion reached in this blog post and seems the likeliest reason. perlunifaq also contains this little gem:

It's good that you lost track, because you shouldn't depend on the internal format being any specific encoding. But since you asked: by default, the internal format is either ISO-8859-1 (latin-1), or utf8, depending on the history of the string. On EBCDIC platforms, this may be different even.

We can conclusively show that warn does something to the string by overriding it. eg:

use strict; use utf8; warn q#warn: ϗblah頁#; $SIG{__WARN__} = sub { print @_ }; warn q#warn: ϗblah頁#;

(As in the OP those should be the actual unicode chars) Here, the second warn generates the wide character error whereas the first does not. To know more about what the default warn handler is doing you would have to start digging in the perl internals.

For other readers: this is all the case under v5.10.1 as reported by peterp, other versions may vary.


In reply to Re: Unexpectedly no wide char error when stderr points at stdout by hippo
in thread Unexpectedly no wide char error when stderr points at stdout by peterp

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.