/[MARC-Fast]/trunk/scripts/dump_fastmarc.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/scripts/dump_fastmarc.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 46 - (show annotations)
Thu Aug 22 10:48:18 2013 UTC (10 years, 8 months ago) by dpavlin
File MIME type: text/plain
File size: 1421 byte(s)
dump tsv file for TokyoCabinet import

1 #!/usr/bin/perl -w
2
3 use strict;
4 use lib 'lib';
5
6 use MARC::Fast;
7 use Getopt::Std;
8 use Data::Dump qw/dump/;
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 =item -t
39
40 dump tsv file for TokyoCabinet import
41
42 =back
43
44 =cut
45
46 my %opt;
47 getopts('do:l:ht', \%opt);
48
49 my $file = shift @ARGV || die "usage: $0 [-o offset] [-l limit] [-h] [-d] file.marc\n";
50
51 my $marc = new MARC::Fast(
52 marcdb => $file,
53 debug => $opt{d},
54 );
55
56
57 my $min = 1;
58 my $max = $marc->count;
59
60 if (my $mfn = $opt{n}) {
61 $min = $max = $mfn;
62 print STDERR "Dumping $mfn only\n";
63 } elsif (my $limit = $opt{l}) {
64 print STDERR "$file has $max records, using first $limit\n";
65 $max = $limit;
66 } else {
67 print STDERR "$file has $max records...\n";
68 }
69
70 for my $mfn ($min .. $max) {
71 my $rec = $marc->fetch($mfn) || next;
72 warn "rec is ",dump($rec) if ($opt{d});
73 if ( $opt{t} ) {
74 print "rec\t$mfn\tleader\t", $marc->last_leader, "\t";
75 my $ascii = $marc->to_ascii($mfn);
76 $ascii =~ s{\n}{\t}gs;
77 print "$ascii\n";
78 } else {
79 print "REC $mfn\n";
80 print $marc->last_leader,"\n";
81 print $marc->to_ascii($mfn),"\n";
82 }
83 warn "hash is ",dump($marc->to_hash($mfn, include_subfields => 1)) if ($opt{h});
84 }

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.26