Created
January 17, 2011 22:49
-
-
Save nichtich/783645 to your computer and use it in GitHub Desktop.
Wandelt PICA+ (egal welche Form) nach JSON (ohne Subfield-Ordnung)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
=head1 NAME | |
pica2json - Wandelt PICA+ (egal welche Form) nach JSON (ohne Subfield-Ordnung) | |
=cut | |
use PICA::Parser qw(parsefile); | |
use JSON; | |
my ($in,$out) = (\*STDIN, *STDOUT); | |
my $json = { }; | |
parsefile( $in, Field => \&handle_field ); | |
binmode $out, ':utf8'; | |
print $out JSON->new->pretty->encode($json); | |
sub handle_field { | |
my $field = shift; | |
my $subfields = { }; | |
foreach my $sf ( $field->content ) { | |
my ($code,$value) = @$sf; | |
push @{ $subfields->{ $code } }, $value; | |
} | |
push @{ $json->{ $field->tag } }, $subfields; | |
undef; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment