X-Git-Url: http://git.rot13.org/?p=MARC-Fast;a=blobdiff_plain;f=scripts%2Fdump_fastmarc.pl;h=f9e96f2fba8d0b90ce5e224dc8761a60da066704;hp=a37171c8b9d71bbbf5f4cd6fdb60b33f471c3473;hb=01a39d84c74ffc4a3553eff9a57a10ae0231a850;hpb=bf7a8cd995686ae3652408d5c58067aba565bf2a diff --git a/scripts/dump_fastmarc.pl b/scripts/dump_fastmarc.pl index a37171c..f9e96f2 100755 --- a/scripts/dump_fastmarc.pl +++ b/scripts/dump_fastmarc.pl @@ -1,38 +1,73 @@ #!/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 + +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}, ); -print STDERR "$file has ",$marc->count," records...\n"; 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"; } -print STDERR "Dumping $min - $max\n" if ($opt{'d'}); - for my $mfn ($min .. $max) { my $rec = $marc->fetch($mfn) || next; + print "rec is ",dump($rec) if ($opt{d}); print "REC $mfn\n"; - foreach my $f (sort keys %{$rec}) { - print "$f\t",$rec->{$f},"\n"; - } - print "\n"; + print $marc->last_leader,"\n"; + print $marc->to_ascii($mfn),"\n"; + print "hash is ",dump($marc->to_hash($mfn, include_subfields => 1)) if ($opt{h}); }