Seekign help with MARC.pm ->as_string
[email protected] ("Migell Acosta")
| Newsgroups | perl.perl4lib |
|---|---|
| Message-ID | <[email protected]> |
Hello all, I am working on a script that will take a MARC record from Baker and Taylor's Title Source and pre-process it so that I can use it in SirsiDynix Symphony 9XX loader - which takes MARC records and converts them into bib records (of course) and Purchase Order records. Mostly my script takes individual subfields in the 949 and re-combines them in several ways so that I get the codes I need. However, I also want to take information in the 951 and do some logic on it, like "if the physical format is 'Paperback' then assign a vendor ID of 1234." So, I need to do pattern matching, I think from the docs I'm supposed to do it like this: if($phys_format->as_string() =~ /Paperback/ ). I think I need the "as_string" in order to do regular expressions, yes? However, what I get back from the interpreter is "Can't locate object method 'as_string' via package Paperback (perhaps you forgot to load Paperback)?" The error is on line 153 of the attached script. I've also attached the MARC record I've been testing. Can anyone help out a newb? Thanks so much. Migell Acosta County of Los Angeles Public Library [email protected] 562-940-8553
test3.pl
(application/octet-stream, 5.6 KB)
## TitleSource 3 to Symphony 3.2 fund code and
## holding code translations.
## by Migell Acosta, County of Los Angeles Public Library
use MARC::Batch;
my $batch = MARC::Batch->new('USMARC','test.mrc');
open(OUT,'>result.mrc') or die $!;
my %location_codes = ('ADULT_SRV' , 'AD',
'AIRC', 'AI',
'APRC', 'AP',
'AUDIOVISUL', 'AV',
'BRC', 'BR',
'CRC', 'CR',
'EB_ENG', 'EE',
'EB_SPAN', 'ES',
'EXEC_OFF', 'EO',
'FACILITIES', 'FA',
'FIC_ENG', 'FI',
'FIC_LARGE', 'FL',
'FIC_SPAN', 'FS',
'FIC_TEEN', 'FT',
'FISCAL_SRV', 'FS',
'HRD', 'HR',
'J_PAPERBCK', 'JP',
'J_REF', 'JR',
'JFIC_ENG', 'JE',
'JFIC_SPAN', 'JS',
'JNF_ENG', 'KE',
'JNF_REF', 'KR',
'JNF_SPAN', 'KS',
'LITERACY', 'LI',
'MARKETING', 'MA',
'NF_ENG', 'NE',
'NF_LARGE', 'NL',
'NF_SPAN', 'NS',
'NF_TEEN', 'NT',
'OFFICE', 'OF',
'PAPERBACKS', 'PB',
'PROF_COLL', 'PR',
'PSA', 'PS',
'REFERENCE', 'RE',
'STAFF_SRV', 'SS',
'TEC_SRV', 'TE',
'YOUTH_SRV', 'YO',
'NETWORK', 'NE',
'MAGAZINES', 'MA');
my %itype_codes = ('AUDIO_CD', 'AC',
'AUDIO_LIT', 'AL',
'AUDIO_TAPE', 'AT',
'BOOK', 'BK',
'BOOK_EB', 'BE',
'BOOKONCD', 'BC',
'BOOKONTAPE', 'BT',
'BOOK_LIT', 'BL',
'BOOK_REF', 'BR',
'CD-ROM', 'CR',
'ENCYCLPDIA', 'EN',
'LARGE_PRNT', 'LP',
'PAPERBACK', 'PB',
'SPOKEN_TPE', 'ST',
'VID_DVD', 'VD',
'VID_LIT', 'VL',
'VID_TAPE', 'VT',
'DOWNLOAD', 'DN',
'MAGAZINE', 'MA',
'ONLINE', 'ON');
my %lang_codes = ('ENG', 'EN',
'SPA', 'SP');
my %audience_codes = ('A', 'ADULT',
'G', 'GENERAL',
'J', 'JUVENILE',
'T', 'TEEN');
## This while loop goes through each MARC record in the batch
while (my $record = $batch->next()) {
## get the language code from the 008 field
my $leader = $record->field('008');
my $lang = uc(substr($leader->as_string, 35, 3));
## get all the 949 fields - there are more than one in each record
my @f949s = $record->field('949');
## examine each 949 field and rename the various subfields
foreach my $field (@f949s) {
my $cost_code = $field->subfield('a');
my $itype = $field->subfield('b');
my $location = $field->subfield('c');
my @flevels = split(/-/,$field->subfield('h'));
my $flevel2 = $flevels[0];
my $flevel3 = $flevels[1];
my $flevel4 = $flevels[2];
my $price = $field->subfield('p');
my $qty = $field->subfield('e');
## gather these all up and make the holding and funding codes
my $holding_code = $cost_code . $itype_codes{$itype} . $location_codes{$location} . $lang_codes{$lang} . $flevel3;
my $funding_code = $cost_code . $flevel2 . $audience_codes{$flevel3} . $flevel4;
## create a new 949 field.
my $new_field = MARC::Field->new(
'949','','', a => $funding_code,
m => $holding_code,
p => $price,
b => $qty);
## replace existing 949 with our new one.
$field->replace_with($new_field);
}
## get all the 951 fields - there are more than one in each record
my @f951s = $record->field('951');
## examine each 951 field and rename the various subfields
foreach my $field (@f951s) {
my $discount_code = $field->subfield('a');
my $line_notes = $field->subfield('b');
my $phys_format = $field->subfield('c');
my $pub_status = $field->subfield('d');
my $list_price = $field->subfield('e');
## examine these fields and determine the vendor ID based on the comparisons below
if($phys_format->as_string() =~ /Paperback/ ){
my $vendorID = "L128820"}
## create a new 951 field.
my $new_field = MARC::Field->new(
'951','','', a => $vendorID);
## replace existing 951 with our new one.
$field->replace_with($new_field);
}
## output modified record.
print OUT $record->as_usmarc();
}
test.mrc
(application/octet-stream, 2.3 KB) - not displayed