Thread Term::ReadKey::ReadKey Codierungsfrage (13 answers)
Opened by Kuerbis at 2014-07-06 21:09

GwenDragon
 2014-07-07 13:31
#176327 #176327
User since
2005-01-17
14538 Artikel
Admin1
[Homepage]
user image
Solange du Encode::Locale nicht sagst, welches Encoding deine Windows-Kosnole verwendet, gehts nicht.
Ich schrieb doch schon, das Modul hat eigene, leider nicht immer korrekte "Rätselmodi" (siehe Modul-Code), um zu erraten wann welches Encoding in der Konsole verwendet wurde.

Code (perl): (dl )
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
#!/usr/bin/env perl
use warnings;
use strict;
use 5.10.1;
use Encode;
use Term::ReadKey;
use Encode::Locale;

Encode::Locale::reinit('cp850'); # set to standard CP850  =Latin1

binmode STDOUT, ":encoding(console_out)";
binmode STDIN, ":encoding(console_in)";

say $Encode::Locale::ENCODING_LOCALE;
say $Encode::Locale::ENCODING_LOCALE_FS;
say $Encode::Locale::ENCODING_CONSOLE_OUT;
say $Encode::Locale::ENCODING_CONSOLE_IN;
say "";

ReadMode 'cbreak';

my $key = ReadKey();
say "|$key|";
$key = decode( 'console_out', $key );
say "|$key|";

ReadMode 'restore';


U:\>chcp
Aktive Codepage: 850.

U:\>test.pl
cp850
cp850
cp850
cp850

"\x{0094}" does not map to cp850 at test.pl line 23.
|\x{0094}|
|ö|


U:\>chcp 1252
Aktive Codepage: 1252.

U:\>test.pl
cp850
cp850
cp850
cp850

|”|
|ö|


Editiert von GwenDragon: Hinweis auf "Erkennung" der Codepage bei Win32
Last edited: 2014-07-07 14:20:49 +0200 (CEST)
die Drachin, Gwendolyn


Unterschiedliche Perl-Versionen auf Windows (fast wie perlbrew) • Meine Perl-Artikel

View full thread Term::ReadKey::ReadKey Codierungsfrage