Thread Unicode Verfremdete Zeichen mit binmode und raw:encoding(UTF-8) (7 answers)
Opened by GoetzM at 2016-07-04 22:27

GoetzM
 2016-07-06 20:38
#185031 #185031
User since
2014-02-26
12 Artikel
BenutzerIn
[default_avatar]
okay, also ein abgewandeltes Kurzbeispiel:

falsch:
open my $_MEM_FH, '<', $chunk_ref;
binmode $_MEM_FH, ':raw:encoding(UTF-8)';
my $c=0;
my $testval=pack "n",1234;
while (<$_MEM_FH>)
{
++$c;

$test{'$c'}=substr($_,0,5).$testval;

}

falsch, weil der Hashwert durch Ableitung aus UTF-8 Inhal als UTF-8 geflaggt ist und automatisch&ungewollt eine Unicodeumwandlung des Binärwertes $testval stattfindet.

so gehts mit "use bytes;":


richtig:
open my $_MEM_FH, '<', $chunk_ref;
binmode $_MEM_FH, ':raw:encoding(UTF-8)';
my $c=0;
my $testval=pack "n",1234;
while (<$_MEM_FH>)
{
++$c;
use bytes;
$test{'$c'}=substr($_,0,5).$testval;

}

View full thread Unicode Verfremdete Zeichen mit binmode und raw:encoding(UTF-8)