Term::Readlineに結果の UTF8 フラグを設定させるにはどうすればよいreadline
ですか?
#!/usr/local/bin/perl
use warnings FATAL => qw(all);
use strict;
use 5.10.1;
use utf8;
use open qw( :encoding(UTF-8) :std );
use Term::ReadLine;
use Devel::Peek;
my $term = Term::ReadLine->new( 'test', *STDIN, *STDOUT );
$term->ornaments( 0 );
my $char;
$char = $term->readline( 'Enter char: ' );
Dump $char;
print 'Enter char: ';
$char = <>;
chomp $char;
Dump $char;
出力:
Enter char: ü
SV = PV(0x11ce4c0) at 0x1090078
REFCNT = 1
FLAGS = (PADMY,POK,pPOK)
PV = 0x14552c0 "\374"\0
CUR = 1
LEN = 16
Enter char: ü
SV = PV(0x11ce4c0) at 0x1090078
REFCNT = 1
FLAGS = (PADMY,POK,pPOK,UTF8)
PV = 0x14552c0 "\303\274"\0 [UTF8 "\x{fc}"]
CUR = 2
LEN = 16
コメント:
mysql
データベースを検索している場合(mysql_enable_utf8
有効):
my $stmt = "SELECT * FROM $table WHERE City REGEXP ?";
say $stmt;
# my $term = Term::ReadLine->new( 'table_watch', *STDIN, *STDOUT );
# $term->ornaments( 0 );
# my $arg = $term->readline( 'Enter argument: ' ); # ü -> doesn't find 'München'
print "Enter argument: ";
my $arg = <>; # ü -> finds 'München'
chomp $arg;