Thread Hash im Methodenaufruf (15 answers)
Opened by bianca at 2014-04-12 10:11

GwenDragon
 2014-04-12 11:20
#174712 #174712
User since
2005-01-17
14748 Artikel
Admin1
[Homepage]
user image
Ich würde statt
Code (perl): (dl )
print JSON->new->$jsoncodierung->encode(\%hash);  
eher so handeln:
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
28
my %hash = ( test => 'ÄÖÜß' );
my $encoding = 'utf8';

use JSON;

package JSON;
sub set_encoding {
  my $self = shift;
  my $encoding = shift;
  return eval "\$self->can($encoding) && \$self->$encoding";
}
1;

my $json = JSON->new;

$json->set_encoding($encoding) or warn "unknown encoding: $encoding";
print $json->encode(\%hash);
     
print "\n";

$encoding = 'latin1';
$json->set_encoding($encoding) or warn "unknown encoding: $encoding";
print $json->encode(\%hash);

print "\n";
$encoding = 'deutsch1968';
$json->set_encoding($encoding) or warn "unknown encoding: $encoding";
print $json->encode(\%hash);

View full thread Hash im Methodenaufruf