/[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

Annotation of /trunk/scripts/dump_fastmarc.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 46 - (hide 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 dpavlin 1 #!/usr/bin/perl -w
2    
3     use strict;
4 dpavlin 37 use lib 'lib';
5 dpavlin 1
6     use MARC::Fast;
7 dpavlin 4 use Getopt::Std;
8 dpavlin 26 use Data::Dump qw/dump/;
9 dpavlin 1
10 dpavlin 7 =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 dpavlin 10 =item -o offset
23 dpavlin 7
24 dpavlin 10 dump records starting with C<offset>
25 dpavlin 7
26     =item -l limit
27    
28 dpavlin 10 dump just C<limit> records
29 dpavlin 7
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 dpavlin 46 =item -t
39    
40     dump tsv file for TokyoCabinet import
41    
42 dpavlin 7 =back
43    
44     =cut
45    
46 dpavlin 4 my %opt;
47 dpavlin 46 getopts('do:l:ht', \%opt);
48 dpavlin 1
49 dpavlin 10 my $file = shift @ARGV || die "usage: $0 [-o offset] [-l limit] [-h] [-d] file.marc\n";
50 dpavlin 4
51 dpavlin 1 my $marc = new MARC::Fast(
52     marcdb => $file,
53 dpavlin 7 debug => $opt{d},
54 dpavlin 1 );
55    
56    
57 dpavlin 4 my $min = 1;
58     my $max = $marc->count;
59    
60 dpavlin 7 if (my $mfn = $opt{n}) {
61 dpavlin 4 $min = $max = $mfn;
62 dpavlin 6 print STDERR "Dumping $mfn only\n";
63 dpavlin 7 } elsif (my $limit = $opt{l}) {
64     print STDERR "$file has $max records, using first $limit\n";
65     $max = $limit;
66 dpavlin 6 } else {
67     print STDERR "$file has $max records...\n";
68 dpavlin 4 }
69    
70     for my $mfn ($min .. $max) {
71 dpavlin 1 my $rec = $marc->fetch($mfn) || next;
72 dpavlin 46 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 dpavlin 1 }

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.26