a37171c8b9d71bbbf5f4cd6fdb60b33f471c3473
[MARC-Fast] / scripts / dump_fastmarc.pl
1 #!/usr/bin/perl -w
2
3 use strict;
4 use blib;
5
6 use MARC::Fast;
7 use Getopt::Std;
8 use Data::Dumper;
9
10 my %opt;
11 getopts('dn:', \%opt);
12
13 my $file = shift @ARGV || die "usage: $0 [-n number] [-d] file.marc\n";
14
15 my $marc = new MARC::Fast(
16         marcdb => $file,
17         debug => $opt{'d'},
18 );
19
20 print STDERR "$file has ",$marc->count," records...\n";
21
22 my $min = 1;
23 my $max = $marc->count;
24
25 if (my $mfn = $opt{'n'}) {
26         $min = $max = $mfn;
27 }
28
29 print STDERR "Dumping $min - $max\n" if ($opt{'d'});
30
31 for my $mfn ($min .. $max) {
32         my $rec = $marc->fetch($mfn) || next;
33         print "REC $mfn\n";
34         foreach my $f (sort keys %{$rec}) {
35                 print "$f\t",$rec->{$f},"\n";
36         }
37         print "\n";
38 }