Moin Moin!
Hallo!
Ich möchte ein Perl-Hash ins JSON-Format kodieren.
Der Hash befülle ich aus einer DB-Abfrage wie folgt:
while (($id, $author, $title) = $dbh->fetchrow_array()) {
$hash{$id} = [$author, $title];
}
>
> wenn ich dann ein
>
> ~~~perl
> use JSON;
> print encode_json \%hash;
>
ausführe, wird mir nichts auf dem Bildschirm ausgegeben.
Kann ich nicht nachvollziehen:
#!/usr/bin/perl
use strict;
use warnings;
use JSON;
my %hash=(
42 => [ "Hein Meier", "Liebesleben der Ameisen" ],
99 => [ "Karl Klein", "Grosses Lexikon" ],
321 => [ "Hugo E. Balder", "Eines Tages ..." ],
);
print encode_json \%hash;
liefert:
{"42":["Hein Meier","Liebesleben der Ameisen"],"99":["Karl Klein","Grosses Lexikon"],"321":["Hugo E. Balder","Eines Tages ..."]}
Alexander
--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so".
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so".