#!/bin/perl use Modern::Perl '2016'; use Getopt::Long; use Catmandu; use File::Basename; use File::Spec; use Log::Any::Adapter; use utf8; if ($^O =~ m/MSWin32/){ binmode STDOUT, ':encoding(cp850)'; } else { binmode STDOUT, ':encoding(utf8)'; } GetOptions( 'debug|d' => \my $debug, 'input|i=s' => \my $input, ); # OS-independent separator my $SEP = File::Spec->catfile("",""); my $dir = File::Spec->rel2abs(dirname(__FILE__)); my $datadir = $dir . $SEP . "data"; if ($debug){ Log::Any::Adapter->set('Log4perl'); Log::Log4perl::init("$dir/data/log4perl.conf"); my $logger = Log::Log4perl->get_logger('myprog'); $logger->info("Starting main program"); } while (!-e $input){ say 'Eingabedatei existiert nicht. Bitte neu angeben:'; chomp ($input = ); } my $output = 'output.mrc'; my $fixfile = 'test.fix'; my $csvfile = "${datadir}${SEP}iso3166H2marc.csv"; say "csv-file path is $csvfile" if -e $csvfile; my $fixer = Catmandu::Fix->new( variables => { ISO2MARC => "$csvfile", }, fixes => [$fixfile], ); my $importer = Catmandu->importer('MARC', file => $input); my $exporter = Catmandu->exporter('JSON', file => $output); my $fixed_importer = $fixer->fix($importer); $exporter->add_many($fixed_importer->benchmark); $exporter->commit; undef($exporter);