7 |
use Getopt::Std; |
use Getopt::Std; |
8 |
use Data::Dumper; |
use Data::Dumper; |
9 |
|
|
10 |
|
=head1 NAME |
11 |
|
|
12 |
|
dump_fastmarc.pl - display MARC records |
13 |
|
|
14 |
|
=head2 USAGE |
15 |
|
|
16 |
|
dump_fastmarc.pl /path/to/dump.marc |
17 |
|
|
18 |
|
=head2 OPTIONS |
19 |
|
|
20 |
|
=over 16 |
21 |
|
|
22 |
|
=item -o offset |
23 |
|
|
24 |
|
dump records starting with C<offset> |
25 |
|
|
26 |
|
=item -l limit |
27 |
|
|
28 |
|
dump just C<limit> records |
29 |
|
|
30 |
|
=item -h |
31 |
|
|
32 |
|
dump result of C<to_hash> on record |
33 |
|
|
34 |
|
=item -d |
35 |
|
|
36 |
|
turn debugging output on |
37 |
|
|
38 |
|
=back |
39 |
|
|
40 |
|
=cut |
41 |
|
|
42 |
my %opt; |
my %opt; |
43 |
getopts('dn:', \%opt); |
getopts('do:l:h', \%opt); |
44 |
|
|
45 |
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"; |
46 |
|
|
47 |
my $marc = new MARC::Fast( |
my $marc = new MARC::Fast( |
48 |
marcdb => $file, |
marcdb => $file, |
49 |
debug => $opt{'d'}, |
debug => $opt{d}, |
50 |
); |
); |
51 |
|
|
52 |
|
|
53 |
my $min = 1; |
my $min = 1; |
54 |
my $max = $marc->count; |
my $max = $marc->count; |
55 |
|
|
56 |
if (my $mfn = $opt{'n'}) { |
if (my $mfn = $opt{n}) { |
57 |
$min = $max = $mfn; |
$min = $max = $mfn; |
58 |
print STDERR "Dumping $mfn only\n"; |
print STDERR "Dumping $mfn only\n"; |
59 |
|
} elsif (my $limit = $opt{l}) { |
60 |
|
print STDERR "$file has $max records, using first $limit\n"; |
61 |
|
$max = $limit; |
62 |
} else { |
} else { |
63 |
print STDERR "$file has $max records...\n"; |
print STDERR "$file has $max records...\n"; |
64 |
} |
} |
65 |
|
|
66 |
for my $mfn ($min .. $max) { |
for my $mfn ($min .. $max) { |
67 |
my $rec = $marc->fetch($mfn) || next; |
my $rec = $marc->fetch($mfn) || next; |
68 |
print Dumper($rec); |
print "rec is ",Dumper($rec) if ($opt{d}); |
69 |
print "REC $mfn\n"; |
print "REC $mfn\n"; |
70 |
foreach my $f (sort keys %{$rec}) { |
print $marc->last_leader,"\n"; |
71 |
print "$f\t", join('', $rec->{$f}) ,"\n"; |
print $marc->to_ascii($mfn),"\n"; |
72 |
} |
print "hash is ",Dumper($marc->to_hash($mfn, include_subfields => 1)) if ($opt{h}); |
|
print "\n"; |
|
|
print Dumper($marc->to_hash($mfn)); |
|
73 |
} |
} |