Last active
July 5, 2020 09:18
-
-
Save jorol/c0d55f30317f7032bf435e8f555ee579 to your computer and use it in GitHub Desktop.
Request data from SRU by ID and store it in an array
This file contains hidden or 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 -w | |
use strict; | |
use warnings; | |
use DDP; | |
use Catmandu::Importer::SRU; | |
# create array to store items | |
my @array = (); | |
# make a single request for each ID and store result in @store | |
while ( my $idn = <DATA> ) { | |
chomp $idn; | |
my $importer = Catmandu::Importer::SRU->new( | |
base => 'https://services.dnb.de/sru/zdb', | |
recordSchema => 'PicaPlus-xml', | |
parser => 'ppxml', | |
query => "idn=$idn", | |
); | |
$importer->each( | |
sub { | |
my $item = shift; | |
# print item ID | |
print "$item->{_id}\n"; | |
# add item to array | |
push @array, $item; | |
} | |
); | |
} | |
# dump array | |
p @array; | |
# save array to file | |
open( my $fh, '>:encoding(UTF-8)', 'pica.dat' ); | |
my $exporter = Catmandu->exporter( 'PICA', type => 'plus', fh => $fh ); | |
foreach my $item (@array) { | |
$exporter->add($item); | |
} | |
$exporter->commit; | |
print "end\n"; | |
__DATA__ | |
010000011 | |
01000002X | |
010000038 | |
010000046 | |
010000054 | |
010000062 | |
010000070 | |
010000089 | |
010000097 | |
010000100 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment