fix for #634
[koha.git] / misc / dumpmarc.pl
1 #!/usr/bin/perl
2 # small script that dumps an iso2709 file.
3
4
5 use strict;
6
7 # Koha modules used
8 use MARC::File::USMARC;
9 use MARC::Record;
10 use MARC::Batch;
11
12 use Getopt::Long;
13 my ( $input_marc_file,$number) = ('',0);
14 my $version;
15 GetOptions(
16     'file:s'    => \$input_marc_file,
17     'n:s' => \$number,
18     'v' => \$version
19 );
20
21 warn "NUM : $number\n";
22 if ($version || ($input_marc_file eq '')) {
23         print <<EOF
24 small script to dump an iso2709 file.
25 parameters :
26 \tv : this version/help screen
27 \tfile /path/to/file/to/dump : the file to dump
28 \tn : the number of the record to dump. If missing, all the file is dumped
29 SAMPLE : ./dumpmarc.pl -file /home/paul/koha.dev/local/npl -n 1
30 EOF
31 ;
32 die;
33 }
34
35 my $batch = MARC::Batch->new( 'USMARC', $input_marc_file );
36 $batch->warnings_off();
37 $batch->strict_off();
38 my $i=1;
39 while ( my $record = $batch->next() ) {
40         print "\nNUMBER $i =>\n".$record->as_formatted() if ($i eq $number || $number eq 0);
41         $i++;
42 }
43 print "\n==================\n$i record parsed\n";