sid_com
sid_com

Reputation: 25117

Term::Readline: encoding-question

When I enter "Müller", on the screen appears "M??ller". How could I fix this?

#!/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

Upvotes: 4

Views: 471

Answers (1)

Alan Haggai Alavi
Alan Haggai Alavi

Reputation: 74252

Apply :utf8 layer to filehandles STDIN and STDOUT, and pass them as arguments to Term::ReadLine->new():

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

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

Upvotes: 7

Related Questions