星期日, 3月 04, 2007

An example perl script to move 852h >dewey< to 942k dewey default for Koha2.2

http://wiki.koha.org/doku.php?id=herea

## Example U2 this is a modified script with thanks to the MARC::Record
## designers and documentation group

use MARC::Batch;
my $batch = MARC::Batch->new('USMARC','/home/mike1/lib4per/MICRO.new');
open(OUT,'>new1.dat') or die $!;
$batch->strict_off();
## read in each record.
while ( my $record = $batch->next() ) {
##fetch 852h
my $good = $record->field('852');
my $goodsub = $good->subfield('h');
## find the tag after 900.
my $before;
foreach ($record->fields()) {
$before = $_;
last if $_->tag() > 900;
}

## create the 942 field.
my $new = MARC::Field->new('942','','',k=>$goodsub);

## insert our 942 field after the $before.
$record->insert_fields_before($before,$new);

## and print out the new record.
print OUT $record->as_usmarc();

}

沒有留言: