I was using MARC.pm wrong. It duplicated records in output
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 1 Feb 2004 20:35:59 +0000 (20:35 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 1 Feb 2004 20:35:59 +0000 (20:35 +0000)
git-svn-id: file:///home/dpavlin/private/svn/webpac/trunk@209 13eb9ef6-21d5-0310-b721-a9d68796d827

tools/dump_marc.pl

index 547525c..ab95c10 100755 (executable)
@@ -8,12 +8,15 @@ my $file = shift @ARGV || die "Usage: $0 [marc file]";
 my $x = new MARC;
 my $nr = $x->openmarc( { file => $file, format => 'usmarc' });
 
-print "file '$file' with '",$x->marc_count(),"' records...\n";
+# read MARC file in memory
+$x->nextmarc(-1);
+
+my $max_rec = $x->marc_count();
 
-while ($x->nextmarc(1)) {
-       print $x->output({format=>'ascii'});    # FIX
+print "file '$file' with '",$x->marc_count(),"' records...\n";
 
-       my $rec = $x->marc_count();
-       print $x->getfirstvalue({record=>$rec,field=>245,subfield=>'a',delimiter=>" "}),"<--\n";
+for(my $i=1; $i<=$max_rec; $i++) {
+       print "REC #$i: ",$x->getfirstvalue({record=>$i,field=>245,subfield=>'a',delimiter=>" "}),"\n";
+       print $x->output({format=>'ascii', record=>$i});
 }