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

Diff of /trunk/scripts/dump_fastmarc.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 4 by dpavlin, Sat Oct 8 16:32:54 2005 UTC revision 46 by dpavlin, Thu Aug 22 10:48:18 2013 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl -w  #!/usr/bin/perl -w
2    
3  use strict;  use strict;
4  use blib;  use lib 'lib';
5    
6  use MARC::Fast;  use MARC::Fast;
7  use Getopt::Std;  use Getopt::Std;
8  use Data::Dumper;  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;  my %opt;
47  getopts('dn:', \%opt);  getopts('do:l:ht', \%opt);
48    
49  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";
50    
51  my $marc = new MARC::Fast(  my $marc = new MARC::Fast(
52          marcdb => $file,          marcdb => $file,
53          debug => $opt{'d'},          debug => $opt{d},
54  );  );
55    
 print STDERR "$file has ",$marc->count," records...\n";  
56    
57  my $min = 1;  my $min = 1;
58  my $max = $marc->count;  my $max = $marc->count;
59    
60  if (my $mfn = $opt{'n'}) {  if (my $mfn = $opt{n}) {
61          $min = $max = $mfn;          $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    
 print STDERR "Dumping $min - $max\n" if ($opt{'d'});  
   
70  for my $mfn ($min .. $max) {  for my $mfn ($min .. $max) {
71          my $rec = $marc->fetch($mfn) || next;          my $rec = $marc->fetch($mfn) || next;
72          print "REC $mfn\n";          warn "rec is ",dump($rec) if ($opt{d});
73          foreach my $f (sort keys %{$rec}) {          if ( $opt{t} ) {
74                  print "$f\t",$rec->{$f},"\n";                  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          print "\n";          warn "hash is ",dump($marc->to_hash($mfn, include_subfields => 1)) if ($opt{h});
84  }  }

Legend:
Removed from v.4  
changed lines
  Added in v.46

  ViewVC Help
Powered by ViewVC 1.1.26