Win32 :: Console :: ANSI和uri_unescape

时间:2013-08-29 09:14:56

标签: perl winapi terminal escaping

当我在带有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

1 个答案:

答案 0 :(得分: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
相关问题