I have two scripts (b1.pl and b2.pl) saved with encoding utf8, the contents of which are shown as follows:
#b1.pl use strict; use utf8; $_="中文"; sub p{ my $_=shift; binmode STDOUT, ":encoding(gbk)"; print "$_\n"; } p($_); p($_); __END__
#b2.pl use strict; use utf8; $_="中文"; binmode STDOUT, ":encoding(gbk)"; print "$_\n";
binmode STDOUT, ":encodinig(gbk)";
binmode STDOUT, ":encoding(gbk)"; print "$_\n"; __END__
In the scripts, 中文 are two chinese characters, which are transformed by perlmonks.In my imagination, the two scripts should have the same output. However, after run under windows xp(chinese edition, edition of perl is activeperl v5.12.2 built for MSWin32-x86-multi-thread), the two scripts have differnt outputs:
e:\home\pl>perl b1.pl perl b1.pl 中文 "\x{0590}" does not map to cp936. "\x{0384}" does not map to cp936. \x{0590}\x{0384} e:\home\pl>perl b2.pl perl b2.pl 中文 中文
I don't have any idea that why the outputs of the two scripts are different. Can any body give me some hints? Thanks.

Thanks to Anynymous Monk. "encodinig" in b2.pl is my stupid typo, I've corrected it.


In reply to weird behaviour of binmode by enroute

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.