Converting MARC records from Sagebrush Athena
I'm looking for comments on my work so far. Here is the perl script I wrote to move things to different fields for Koha. Let me know if you see anything that should be changed or could be done a better way. I'm still learning perl, so this could look pretty bad. First I set up a hash for converting Athena formats to Koha item types. After I read a record, I pick the data I want from the 852 fields. 852_6 is format 852_p is barcode 852_9 is cost 852_8 is accession date 852_k is call number prefix 852_k is call number main 852_i is call number cutter 852_m is call number suffix 852_9 is changed to pull any extra characters out of the cost. Athena allows longer strings for their formats. 852_9 is changed to shorter strings using the hash made at the start of the script. Build a whole call number from the pieces in 852 by putting $k, $h, $i and $m together with spaces between and then stripping extra spaces out of it. Put 952 together with our new 852_9, our new call, a code for the home branch and holding branch and the barcode. #!/usr/bin/perl # use strict; # use warnings; ## Crate our MARC::Batch object. use MARC::Batch; my $infile = $ARGV[0]; my $outfile = $ARGV[1]; my $batch = MARC::Batch->new('USMARC',$infile); ## open a file handle to write to. open(OUT,">$outfile") or die $!; my %format = ( 'binder' => BIND, 'book' => BOOK, 'book kit' => KIT, 'books on CD' => BKCD, 'books on tape' => BKTP, 'cbook' => BOOK, 'CD' => CD, 'CD-ROM' => CD, 'DVD' => DVD, 'ebook' => BOOK, 'equipment' => EQU, 'file folder' => FILE, 'frame' => FRAM, 'hbook' => BOOK, 'magazine' => MAG, 'map' => MAP, 'sbook' => BOOK, 'tboot' => BOOK, 'vbook' => BOOK, 'video' => VID ); ## read each record. modify, then print. while ( my $record = $batch->next() ) { ## get info from 852 field. my @fields = $record->field('852'); foreach my $field (@fields) { $field852_6=$field->subfield('6'); $field852_p=$field->subfield('p'); $field852_9=$field->subfield('9'); $field852_8=$field->subfield('8'); $field852_k=$field->subfield('k'); $field852_h=$field->subfield('h'); $field852_i=$field->subfield('i'); $field852_m=$field->subfield('m'); $field852_9 =~ s/[^0-9.]//ig; ## change the format in 852 6 my $new_field=$format{$field852_6}; $field->update( 6 => $new_field ); ## Make a new call number for 952 a $call=$field852_k . ' ' . $field852_h . ' ' . $field852_i . ' ' . $field852_m; while ($call=~s/ / /ig) {} $call=~s/^ //; $call=~s/ $//; ## add 952 field from 852 tags $record->append_fields( MARC::Field->new('952','','',8=>$field852_8, 9=>$field852_9, a=>$call, b=>'WLPL', d=>'WLPL', p=>$field852_p)); print OUT $record->as_usmarc(); }} close(OUT); _______________________________________________ Koha mailing list Koha@lists.katipo.co.nz http://lists.katipo.co.nz/mailman/listinfo/koha
participants (1)
-
Tim McMahon - West Liberty Public Library