1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
#!/usr/bin/perl -w
use strict;
use lib 'lib';
use MARC::Fast;
use Getopt::Std;
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<offset>
=item -l limit
dump just C<limit> records
=item -h
dump result of C<to_hash> on record
=item -d
turn debugging output on
=item -t
dump tsv file for TokyoCabinet import
=back
=cut
my %opt;
getopts('do:l:ht', \%opt);
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},
);
my $min = 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 = $limit;
} else {
print STDERR "$file has $max records...\n";
}
for my $mfn ($min .. $max) {
my $rec = $marc->fetch($mfn) || next;
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});
}
|