X-Git-Url: http://git.rot13.org/?p=MARC-Fast;a=blobdiff_plain;f=scripts%2Fdump_fastmarc.pl;h=b1d87023e2a77da918a34b2e3ef6e82dcb817d79;hp=538f8ead6ab3874c73571bb686e4381b75409b51;hb=79218e828e9e2e78f8b8c0f54be1ca9b99937d55;hpb=8300e4b53e83d8a355dba26d74624d521f67232f diff --git a/scripts/dump_fastmarc.pl b/scripts/dump_fastmarc.pl index 538f8ea..b1d8702 100755 --- a/scripts/dump_fastmarc.pl +++ b/scripts/dump_fastmarc.pl @@ -7,34 +7,72 @@ use MARC::Fast; use Getopt::Std; use Data::Dumper; +=head1 NAME + +dump_fastmarc.pl - display MARC records + +=head2 USAGE + + dump_fastmarc.pl /path/to/dump.marc + +=head2 OPTIONS + +=over 16 + +=item -o offset + +dump records starting with C + +=item -l limit + +dump just C records + +=item -h + +dump result of C on record + +=item -d + +turn debugging output on + +=back + +=cut + my %opt; -getopts('dn:', \%opt); +getopts('do:l:h', \%opt); -my $file = shift @ARGV || die "usage: $0 [-n number] [-d] file.marc\n"; +my $file = shift @ARGV || die "usage: $0 [-o offset] [-l limit] [-h] [-d] file.marc\n"; my $marc = new MARC::Fast( marcdb => $file, - debug => $opt{'d'}, + debug => $opt{d}, ); my $min = 1; my $max = $marc->count; -if (my $mfn = $opt{'n'}) { +if (my $mfn = $opt{n}) { $min = $max = $mfn; print STDERR "Dumping $mfn only\n"; +} elsif (my $limit = $opt{l}) { + print STDERR "$file has $max records, using first $limit\n"; + $max = $limit; } else { print STDERR "$file has $max records...\n"; } for my $mfn ($min .. $max) { my $rec = $marc->fetch($mfn) || next; - print Dumper($rec); + print "rec is ",Dumper($rec) if ($opt{d}); print "REC $mfn\n"; foreach my $f (sort keys %{$rec}) { - print "$f\t", join('', $rec->{$f}) ,"\n"; + my $dump = join('', @{ $rec->{$f} }); + $dump =~ s/\x1e$//; + $dump =~ s/\x1f/\$/g; + print "$f\t$dump\n"; } print "\n"; - print Dumper($marc->to_hash($mfn)); + print "hash is ",Dumper($marc->to_hash($mfn)) if ($opt{h}); }