pod documentation, new options, much nicer output
authorDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 28 Dec 2005 22:03:24 +0000 (22:03 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 28 Dec 2005 22:03:24 +0000 (22:03 +0000)
git-svn-id: svn+ssh://llin/home/dpavlin/private/svn/MARC-Fast/trunk@7 49f9634a-d7ec-0310-8e6b-ec35c6cc8804

scripts/dump_fastmarc.pl

index 538f8ea..eb0fd0c 100755 (executable)
@@ -7,34 +7,72 @@ use MARC::Fast;
 use Getopt::Std;
 use Data::Dumper;
 
+=head1 NAME
+
+dump_fastmarc.pl - display MARC records
+
+=head2 USAGE
+
+  dump_fastmarc.pl /path/to/dump.marc
+
+=head2 OPTIONS
+
+=over 16
+
+=item -n number
+
+dump just record C<number>
+
+=item -l limit
+
+import just first C<limit> records
+
+=item -h
+
+dump result of C<to_hash> on record
+
+=item -d
+
+turn debugging output on
+
+=back
+
+=cut
+
 my %opt;
-getopts('dn:', \%opt);
+getopts('dn:l:h', \%opt);
 
-my $file = shift @ARGV || die "usage: $0 [-n number] [-d] file.marc\n";
+my $file = shift @ARGV || die "usage: $0 [-n number] [-l limit] [-h] [-d] file.marc\n";
 
 my $marc = new MARC::Fast(
        marcdb => $file,
-       debug => $opt{'d'},
+       debug => $opt{d},
 );
 
 
 my $min = 1;
 my $max = $marc->count;
 
-if (my $mfn = $opt{'n'}) {
+if (my $mfn = $opt{n}) {
        $min = $max = $mfn;
        print STDERR "Dumping $mfn only\n";
+} elsif (my $limit = $opt{l}) {
+       print STDERR "$file has $max records, using first $limit\n";
+       $max = $limit;
 } else {
        print STDERR "$file has $max records...\n";
 }
 
 for my $mfn ($min .. $max) {
        my $rec = $marc->fetch($mfn) || next;
-       print Dumper($rec);
+       print "rec is ",Dumper($rec) if ($opt{d});
        print "REC $mfn\n";
        foreach my $f (sort keys %{$rec}) {
-               print "$f\t", join('', $rec->{$f}) ,"\n";
+               my $dump = join('', @{ $rec->{$f} });
+               $dump =~ s/\x1e$//;
+               $dump =~ s/\x1f/\$/g;
+               print "$f\t$dump\n";
        }
        print "\n";
-       print Dumper($marc->to_hash($mfn));
+       print "hash is ",Dumper($marc->to_hash($mfn)) if ($opt{h});
 }