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