added option -n number to dump just one record and -d for debug
[MARC-Fast] / scripts / dump_fastmarc.pl
index 1257ac3..a37171c 100755 (executable)
@@ -4,20 +4,31 @@ use strict;
 use blib;
 
 use MARC::Fast;
-
+use Getopt::Std;
 use Data::Dumper;
 
-my $file = shift @ARGV || die "usage: $0 file.marc\n";
-my $debug = shift @ARGV;
+my %opt;
+getopts('dn:', \%opt);
+
+my $file = shift @ARGV || die "usage: $0 [-n number] [-d] file.marc\n";
 
 my $marc = new MARC::Fast(
        marcdb => $file,
-       debug => $debug,
+       debug => $opt{'d'},
 );
 
-print STDERR "$file has ",$marc->count," records...\n\n";
+print STDERR "$file has ",$marc->count," records...\n";
+
+my $min = 1;
+my $max = $marc->count;
+
+if (my $mfn = $opt{'n'}) {
+       $min = $max = $mfn;
+}
+
+print STDERR "Dumping $min - $max\n" if ($opt{'d'});
 
-for my $mfn (1 .. $marc->count) {
+for my $mfn ($min .. $max) {
        my $rec = $marc->fetch($mfn) || next;
        print "REC $mfn\n";
        foreach my $f (sort keys %{$rec}) {