X-Git-Url: http://git.rot13.org/?p=MARC-Fast;a=blobdiff_plain;f=scripts%2Fdump_fastmarc.pl;h=a9400070af236b8448028dd2aa11235437bd0523;hp=efce95487f2d964b3efefe6da4ac133470c52715;hb=3c02257514b1f105c8a3b3aec9b7e0dfdd932f96;hpb=3d844dfbf091bc62a45aff80189d402d1f9cba1f diff --git a/scripts/dump_fastmarc.pl b/scripts/dump_fastmarc.pl index efce954..a940007 100755 --- a/scripts/dump_fastmarc.pl +++ b/scripts/dump_fastmarc.pl @@ -1,11 +1,11 @@ #!/usr/bin/perl -w use strict; -use blib; +use lib 'lib'; use MARC::Fast; use Getopt::Std; -use Data::Dumper; +use Data::Dump qw/dump/; =head1 NAME @@ -27,6 +27,10 @@ dump records starting with C 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 @@ -35,22 +39,25 @@ dump result of C on record turn debugging output on +=item -t + +dump tsv file for TokyoCabinet import + =back =cut my %opt; -getopts('do:l:h', \%opt); +getopts('do:l:n:ht', \%opt); -my $file = shift @ARGV || die "usage: $0 [-o offset] [-l limit] [-h] [-d] file.marc\n"; +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 => $opt{d}, ); - -my $min = 1; +my $min = $opt{o} || 1; my $max = $marc->count; if (my $mfn = $opt{n}) { @@ -58,16 +65,23 @@ if (my $mfn = $opt{n}) { print STDERR "Dumping $mfn only\n"; } elsif (my $limit = $opt{l}) { print STDERR "$file has $max records, using first $limit\n"; - $max = $limit; + $max = $min + $limit - 1; } else { print STDERR "$file has $max records...\n"; } for my $mfn ($min .. $max) { my $rec = $marc->fetch($mfn) || next; - print "rec is ",Dumper($rec) if ($opt{d}); - print "REC $mfn\n"; - print $marc->last_leader,"\n"; - print $marc->to_ascii($mfn),"\n"; - print "hash is ",Dumper($marc->to_hash($mfn, include_subfields => 1)) if ($opt{h}); + 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"; + } + warn "hash is ",dump($marc->to_hash($mfn, include_subfields => 1)) if ($opt{h}); }