1 |
#!/usr/bin/perl -w |
#!/usr/bin/perl -w |
2 |
|
|
3 |
use strict; |
use strict; |
4 |
use MARC; |
use MARC::File::USMARC; |
5 |
|
use Data::Dumper; |
6 |
|
|
7 |
my $file = shift @ARGV || die "Usage: $0 [marc file]"; |
my $file = shift @ARGV || die "Usage: $0 [marc file]"; |
8 |
|
|
9 |
my $x = new MARC; |
my $marc_file = MARC::File::USMARC->in($file) || die $MARC::File::ERROR; |
|
my $nr = $x->openmarc( { file => $file, format => 'usmarc' }); |
|
10 |
|
|
11 |
# read MARC file in memory |
sub marc_count { |
12 |
$x->nextmarc(-1); |
my $filename = shift || die; |
13 |
|
my $file = MARC::File::USMARC->in($filename) || die $MARC::File::ERROR; |
14 |
my $max_rec = $x->marc_count(); |
my $count = 0; |
15 |
|
while ($file->skip()) { |
16 |
|
$count++; |
17 |
|
} |
18 |
|
return $count; |
19 |
|
} |
20 |
|
|
21 |
print "file '$file' with '",$x->marc_count(),"' records...\n"; |
print "file '$file' with ",marc_count($file)," records...\n"; |
22 |
|
|
23 |
for(my $i=1; $i<=$max_rec; $i++) { |
while( my $marc = $marc_file->next() ) { |
24 |
print "REC #$i: ",$x->getfirstvalue({record=>$i,field=>245,subfield=>'a',delimiter=>" "}),"\n"; |
print "REC #",$marc->field('001')->as_string,": ",$marc->title,"\n"; |
25 |
print $x->output({format=>'ascii', record=>$i}); |
print $marc->as_formatted,"\n\n"; |
26 |
} |
} |
27 |
|
|