perl 特殊字符 windows

perl special char windows

我尝试在 ma perl 控制台应用程序的输出中使用德语特殊字符:öäüßÖÄÜ,但我失败了。德系win7系统,活动代码页850

#!/usr/bin/perl 
use warnings;
use strict;

binmode(STDOUT , ":encoding(cp437)" )  if $^O eq 'MSWin32';
#binmode(STDOUT , ":encoding(cp850)" )  if $^O eq 'MSWin32';
#binmode(STDOUT , ":encoding(cp1252)" ) if $^O eq 'MSWin32';

my @sp_chars = qw/ä ö ü ß Ä Ö Ü/;

foreach my $sp_char ( @sp_chars ) {
  print "$sp_char\n";
}

我收到如下错误:

"\x{009f}" does not map to cp1252 at umlaute.pl line 12.

"\x{009f}" does not map to cp850 at umlaute.pl line 12.

"\x{00c3}" does not map to cp437 at umlaute.pl line 12.

如何获得合适的输出?

在源代码中使用utf8字符并使用IO层进行编码时,应在perl解析器中打开utf8:

use utf8; 

my $encoding = $^O eq 'MSWin32' ? 'cp850' : 'utf8';
binmode(STDOUT, ":encoding($encoding)" );

print "$_\n" for qw/ä ö ü ß Ä Ö Ü/;