1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#!perl use warnings; use strict; use 5.10.0; use utf8; use Encode; use Devel::Peek; use Encode::Locale; #Encode::Locale::reinit('utf-8'); binmode STDIN, ':encoding(console_in)'; binmode STDOUT, ':encoding(console_out)'; binmode STDERR, ':encoding(console_out)'; use Term::ReadKey; ReadMode 3; my $c = ReadKey; $c = decode( 'console_in', $c ); Dump $c; say "[$c]"; ReadMode 0; use Win32::Console; my $in = Win32::Console->new( STD_INPUT_HANDLE ); $in->Mode( ENABLE_PROCESSED_INPUT ); my $char = $in->InputChar(); $char = decode( 'console_in', $char ); Dump $char; say "{$char}";
type Datei_mit_Smily.txt | perl.pl
1 2 3 4 5 6 7 8 9
use Term::ReadKey; use Encode::Locale; ReadMode 3; my $c = ReadKey; $c = decode( 'console_in', $c ); Dump $c; say "[$c]"; ReadMode 0;
GetConsoleMode failed, LastError=|6| at C:/strawberry/perl/vendor/lib/Term/ReadKey.pm line 309.
1 2 3 4 5 6 7
use Win32::Console; my $in = Win32::Console->new( STD_INPUT_HANDLE ); $in->Mode( ENABLE_PROCESSED_INPUT ); my $char = $in->InputChar(); #$char = decode( 'console_in', $char ); Dump $char; say "{$char}";
1
2
3
4
5
6
C:\Users\mm>type multibyte.txt | perl.pl
SV = NULL(0x0) at 0x12fe81c
REFCNT = 1
FLAGS = (PADMY)
Use of uninitialized value $char in concatenation (.) or string at C:\Users\mm\perl.pl line 23.
{}