Michael Doran Home Page
Contact | Site Map | Search  
  Home > MARC.pm & Prebulk > Process > netlib03.pl

netlib03.pl


#!/usr/local/bin/perl -w

###############################################
#
#  Perl script: netlib03.pl
#  
#  A Perl/MARC.pm script to preprocess
#  a file of netLibrary records.
#
#  2001, Michael Doran, doran@uta.edu
#
#  Adapted and modified from a VUGM 2001
#  session handout by David Bennett.
#
#  Notice: Quick hack; use at your own risk.
#  No warranties, etc., etc.
#
###############################################

use MARC;

if (! ($#ARGV == 1)) {
    print "Usage: $0 input_file output_file\n";
    exit(1);
}

$infile  = shift;
$outfile = shift;

if ( ! -f $infile ) {
    print "$0: can't find $infile...exiting\n";
    exit(1);
}  

if ( -f $outfile ) {
    print "$0: $outfile already exists...exiting\n";
    exit(1);
}

$x = new MARC;
$x->openmarc({file=>"$infile",'format'=>"usmarc"});
while ($x->nextmarc(1)) {
    my $field_856   = {record=>1,field=>'856',rebuild_map=>1};
    my @data_856    = $x->getfields($field_856);
    foreach my $entry (@data_856) {
        my $ind_1       = $x->getmatch('i1',$entry);
        my $ind_2       = $x->getmatch('i2',$entry);
        $$ind_1         = "4";
        $$ind_2         = "0";
    }
    $x->rebuild_map(1,856);
    $x->output({file=>">>$outfile",'format'=>"usmarc"});
    $x->deletemarc(); #empty the object for reading in another
}        
$x->closemarc();

exit(0);