X-Git-Url: http://git.rot13.org/?p=MARC-Fast;a=blobdiff_plain;f=scripts%2Fdump_fastmarc.pl;h=a9400070af236b8448028dd2aa11235437bd0523;hp=1257ac361a2f0312f7e04c90aa94e08d67730ac6;hb=3c02257514b1f105c8a3b3aec9b7e0dfdd932f96;hpb=eb411e96a84d82b31bc173025803b2d7dd8ab404 diff --git a/scripts/dump_fastmarc.pl b/scripts/dump_fastmarc.pl index 1257ac3..a940007 100755 --- a/scripts/dump_fastmarc.pl +++ b/scripts/dump_fastmarc.pl @@ -1,27 +1,87 @@ #!/usr/bin/perl -w use strict; -use blib; +use lib 'lib'; use MARC::Fast; +use Getopt::Std; +use Data::Dump qw/dump/; -use Data::Dumper; +=head1 NAME -my $file = shift @ARGV || die "usage: $0 file.marc\n"; -my $debug = shift @ARGV; +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 -n mfn + +dump single C record (same as C<-o mfn -l 1>) + +=item -h + +dump result of C on record + +=item -d + +turn debugging output on + +=item -t + +dump tsv file for TokyoCabinet import + +=back + +=cut + +my %opt; +getopts('do:l:n:ht', \%opt); + +my $file = shift @ARGV || die "usage: $0 [-o offset] [-l limit] [-n single_mfn] [-h] [-d] [-t] file.marc\n"; my $marc = new MARC::Fast( marcdb => $file, - debug => $debug, + debug => $opt{d}, ); -print STDERR "$file has ",$marc->count," records...\n\n"; +my $min = $opt{o} || 1; +my $max = $marc->count; + +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 = $min + $limit - 1; +} else { + print STDERR "$file has $max records...\n"; +} -for my $mfn (1 .. $marc->count) { +for my $mfn ($min .. $max) { my $rec = $marc->fetch($mfn) || next; - print "REC $mfn\n"; - foreach my $f (sort keys %{$rec}) { - print "$f\t",$rec->{$f},"\n"; + warn "rec is ",dump($rec) if ($opt{d}); + if ( $opt{t} ) { + print "rec\t$mfn\tleader\t", $marc->last_leader, "\t"; + my $ascii = $marc->to_ascii($mfn); + $ascii =~ s{\n}{\t}gs; + print "$ascii\n"; + } else { + print "REC $mfn\n"; + print $marc->last_leader,"\n"; + print $marc->to_ascii($mfn),"\n"; } - print "\n"; + warn "hash is ",dump($marc->to_hash($mfn, include_subfields => 1)) if ($opt{h}); }