}
} elsif ($type_base eq "marc") {
- require MARC;
+ require MARC::File::USMARC;
$import2cp = Text::Iconv->new($config->{marc_codepage},$codepage);
my $marc_file = $cfg -> val($database, 'marc_file') || die "$database doesn't have 'marc_file' defined!";
# optional argument is format
- my $format = x($config->{marc_format}) || 'usmarc';
-
+ warn "marc_format is no longer used!" if ($config->{marc_format});
print STDERR "Reading MARC file '$marc_file'\n";
- my $marc = new MARC;
- my $nr = $marc->openmarc({
- file=>$marc_file, format=>$format
- }) || die "Can't open MARC file '$marc_file' with format '$format'";
+ my $marc = MARC::File::USMARC->in( $marc_file )
+ || die "Can't open MARC file '$marc_file': ".$MARC::File::ERROR;
- # read MARC file in memory
- $marc->nextmarc(-1);
+ # count records in MARC file
+ 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;
+ }
- my $max_rec = $marc->marc_count();
+ my $count = marc_count($marc_file) || warn "no records in '$marc_file'?";
- for(my $i=1; $i<=$max_rec; $i++) {
+ my $i = 0;
- progress($i,$max_rec);
+ while( my $rec = $marc->next() ) {
- # store value for marc_sf.pm
- $main::cache->{marc_record} = $i;
+ progress($i++,$count);
my $swishpath = $database."#".$i;
- if (my $xml = data2xml($type_base,$marc,$add_xml,$cfg,$database)) {
+ if (my $xml = data2xml($type_base,$rec,$add_xml,$cfg,$database)) {
$xml = $cp2utf->convert($xml);
use bytes; # as opposed to chars
print "Path-Name: $swishpath\n";
my $i = shift @_ || 0;
- my $rec = $main::cache->{marc_record} || die '$cache->{marc_record} is undefined!';
-
- my @out = $marc->getvalue({record=>$rec,field=>$f,subfield=>$s});
+ my @out;
+ if ($s) {
+ @out = $marc->subfield($f,$s);
+ } else {
+ @out = $marc->field($f)->as_string() if ($marc->field($f));
+ }
return $out[$i] if (@out && $out[$i]);
}