--- branches/drustvene/tools/dump_marc.pl 2004/12/22 15:47:21 602 +++ branches/drustvene/tools/dump_marc.pl 2004/12/27 21:00:20 603 @@ -1,22 +1,27 @@ #!/usr/bin/perl -w use strict; -use MARC; +use MARC::File::USMARC; 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}); +my $i = 1; +while( my $marc = $marc_file->next() ) { + print "REC #",$i++,": ",$marc->title,"\n"; + print $marc->as_formatted,"\n\n"; }