Term :: Readline:encoding-question

时间:2011-02-11 07:36:30

标签: perl encoding terminal readline

当我进入“Müller”时,屏幕上出现“M ?? ller”。我怎么能解决这个问题?

#!/usr/bin/env perl
use warnings;
use 5.012;
use Term::ReadLine;

my $term = Term::ReadLine->new( 'dummy' );

my $con = $term->readline( ': ' );

say $con;

# On the screen:
# : M��ller                                                                                                                                                   
# Müller

1 个答案:

答案 0 :(得分:7)

:utf8图层应用于文件句柄STDINSTDOUT,并将其作为参数传递给Term::ReadLine->new()

binmode STDIN,  ':utf8';
binmode STDOUT, ':utf8';

my $term = Term::ReadLine->new( 'dummy', \*STDIN, \*STDOUT );