upgrade from MARC to MARC::File::USMARC, take MFN from data
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 1 Jan 2005 18:15:40 +0000 (18:15 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 1 Jan 2005 18:15:40 +0000 (18:15 +0000)
M    dump_marc.pl

git-svn-id: file:///home/dpavlin/private/svn/webpac/trunk@619 13eb9ef6-21d5-0310-b721-a9d68796d827

tools/dump_marc.pl

index ab95c10..24301fc 100755 (executable)
@@ -1,22 +1,27 @@
 #!/usr/bin/perl -w
 
 use strict;
-use MARC;
+use MARC::File::USMARC;
+use Data::Dumper;
 
 my $file = shift @ARGV || die "Usage: $0 [marc file]";
 
-my $x = new MARC;
-my $nr = $x->openmarc( { file => $file, format => 'usmarc' });
+my $marc_file = MARC::File::USMARC->in($file) || die $MARC::File::ERROR;
 
-# read MARC file in memory
-$x->nextmarc(-1);
-
-my $max_rec = $x->marc_count();
+sub marc_count {
+       my $filename = shift || die;
+       my $file = MARC::File::USMARC->in($filename) || die $MARC::File::ERROR;
+       my $count = 0;
+       while ($file->skip()) {
+               $count++;
+       }
+       return $count;
+}
 
-print "file '$file' with '",$x->marc_count(),"' records...\n";
+print "file '$file' with ",marc_count($file)," records...\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});
+while( my $marc = $marc_file->next() ) {
+       print "REC #",$marc->field('001')->as_string,": ",$marc->title,"\n";
+       print $marc->as_formatted,"\n\n";
 }