[Vienna-pm] utf8 string als hash-key

max prozessor13 at gmx.net
Mon Sep 21 03:30:16 PDT 2009


so und nochmal.

jetzt hab ich das beweis-script:

use strict;
use utf8;
use Data::Dumper;
binmode STDOUT, 'utf8';

sub x {
   my %hash = map {
      my $k = $_;
      utf8::encode($k);
      $k => 'bytes'
   } @_;
   foreach (keys %hash) {
      my $k = $_;
      utf8::decode($k);
      $hash{$k} = 'utf8';
   }
   return \%hash;
}

my $x = 'öäü';
my $h = x($x);
print Data::Dumper->Dumpperl([$h]);
print Data::Dumper->Dump([$h]);

liefert unter perl5.8.9 korrekterweise:

$VAR1 = {
          'öäü' => 'bytes',
          'öäü' => 'utf8'
        };
$VAR1 = {
          'öäü' => 'bytes',
          "\x{f6}\x{e4}\x{fc}" => 'utf8'
        };

und unter perl 5.10 falscherweise:

$VAR1 = {
          'öäü' => undef,
          'öäü' => 'bytes',
          'öäü' => ${\$VAR1->{'öäü'}}
        };
$VAR1 = {
          "\x{f6}\x{e4}\x{fc}" => 'utf8',
          'öäü' => 'bytes',
          "\x{f6}\x{e4}\x{fc}" => undef
        };

k.a. wieso da 3 keys drinnen sind, und zusaetzlich verliert der perl- 
varante im gegensatz zur xs variante auch noch eine hash-value.

grrr... ich weiss nicht, ob ich hier eine loesung schaffen kann...


More information about the Vienna-pm mailing list