0

当我在带有 CP850 的 WinXP 终端中运行此脚本时,Ü并且ö显示正确。当我取消注释该use Win32::Console::ANSI;行时,输出被破坏。
这种行为是可以预期的还是这是一个错误?

#!perl
use warnings;
use strict;
use 5.10.0;
binmode STDOUT, ':encoding(cp850)';

use Encode qw(decode_utf8);
use URI::Escape qw(uri_unescape);
#use Win32::Console::ANSI;

my $uri_escaped = '%C3%9Cberraschungsei+R%C3%B6ntgen';
say $uri_escaped;

my $uri_unescaped = uri_unescape( $uri_escaped );
say $uri_unescaped;

my $utf8_decoded = decode_utf8( $uri_unescaped );
say "Result: $utf8_decoded";

%C3%9Cberraschungsei+R%C3%B6ntgen
"\x{009c}" does not map to cp850 at C:perl.pl line 15.
Ã\x{009c}berraschungsei+Röntgen
Result: Überraschungsei+Röntgen

启用Win32::Console::ANSI后:

%C3%9Cberraschungsei+R%C3%B6ntgen
"\x{009c}" does not map to cp850 at C:perl.pl line 15.
Ç\x{009c}berraschungsei+RÇôntgen
Result: sberraschungsei+R"ntgen
4

1 回答 1

2

使用 ANSI 代码页 (cp1252) 而不是 OEM 代码页。

>chcp
Active code page: 437

>perl a.pl cp437
%C3%9Cberraschungsei+R%C3%B6ntgen
Überraschungsei+Röntgen

>perl -MWin32::Console::ANSI a.pl cp1252
%C3%9Cberraschungsei+R%C3%B6ntgen
Überraschungsei+Röntgen
于 2013-08-29T11:35:13.627 回答