/[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 10 - (hide annotations)
Fri Nov 3 20:07:58 2006 UTC (17 years, 5 months ago) by dpavlin
File MIME type: text/plain
File size: 1263 byte(s)
change terminology to offset and limit

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

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.26