Re: converting data for subfields in 1XX
[email protected] ("Saiful Amin")
| Newsgroups | perl.perl4lib |
|---|---|
| Message-ID | <[email protected]> |
Hi Jackie, Sorry for the delay, I was travelling past one week and couldn't get my hand on this one. I've done two changes and it works now. Attached is the edited script. 1. Pipe (|) is a special character in Perl and it needs to escaped (\|) on line 88. 2. I'm not sure on the 'binmode' function to work on this module. I guess you might have to use MARC::Charset::UTF8 or something similar. Hope this helps. Cheers, Saiful On 11/3/06, Jackie Shieh <[email protected]> wrote: > > > Here is what I have... not working ver well. > See attached. > > perl: pam2.pl > input: FpamTest.txt > outpu: Testout.dat > > > On Thu, 2 Nov 2006, Saiful Amin wrote: > > > Hi, > > > > Can you share your code? > > > > -Saiful > > > > On 11/2/06, Jackie Shieh <[email protected]> wrote: > >> > >> > >> I have a tab delimited text file of 8 columns. Its 1st column > >> contains author entry (most are main entry, others not) like > >> this below. > >> > >> > >> 1001 |a Du Moulin, Pierre, |d 1568-1658 > >> 11010|a France. |b Conseil d'Etat > >> 1001 |a Vendme, Csar de Bourbon, |c duc de, |d 1594-1665. > >> 130 0|a Interim of Augsburg (1548) > >> 1001 |a Morgues, Matthieu de, |c sieur de Saint-Germain, |d 1582-1670. > >> 10010|a Jouan, Abel. > >> 7201 |a [Du Moulin, Pierre], |d 1568-1658 > >> 7201 |a Henrici IV. Christianissimi Franciae et Navarrae regis > >> 1001 |a Morgues, Matthieu de, |c sieur de Saint-Germain, |d 1582-1670. > >> 151 |a United Provinces of the Netherlands > >> 10010|a Sirmond, Jean, |d 1589?-1649 > >> 1001 |a Scudry, |c M. de |q (Georges), |d 1601-1667 > >> 1001 |a Grenaille, |c M. de |q (Franois), |c sieur de Chatounieres, |d > >> 1616-1680. > >> 10010|a Sable, Abel Servien, |c marquis de, |d 1593-1669. > >> > >> > >> I was successful in getting the tag and indicators proper placed > >> using MARC::Record. > >> > >> At this time, I am strugging of putting the data beyond subfield a > >> in its proper subfield code and position. I was wondering if anyone > >> has come across something like this and have already had a solution > >> to this? Thank you very much for your help! > >> > >> Regards, > >> > >> --Jackie > >> > >> |Jackie Shieh > >> |Special Projects & Collections Team > >> |Harlan Hatcher Graduate Library > >> |University of Michigan > >> |920 North University > >> |Ann Arbor, MI 48109-1205 > >> |Phone: 734.936.2401 FAX: 734.615.9788 > >> |E-mail: [email protected] > >> > -- Saiful Amin Information Specialist Edutech India 2/2, Union Street Off Infantry Road Bangalore 560001, India Tel: +91 80 4112 3437 M: +91 93438 26438 Fax: +91 80 4151 7801 www.edutechindia.com "Enhancing knowledge and skills for success, lifelong."
pam2.pl
(application/octet-stream, 3.2 KB)
#!/usr/bin/perl
## 7054 entries; test file 27 entries
##
## 2006-10
## convert to MARC21; fix proper format later
use warnings;
use strict;
use MARC::Batch;
use MARC::Record;
use MARC::Field;
my ($input,$output) = @ARGV;
die "couldn't find $input" if !(-e $input);
# my $batch = MARC::Batch->new('USMARC', $input);
open (IN, "$input");
open (OUT, ">$output");
#binmode OUT, ':utf8';
while ( my $line = <IN> ) {
chomp ($line);
$line =~ s/"//g;
my ($author,$lang, $title,$pubInfo,$ctry,$pdate,$note,$reel) = split /\t/, $line;
chomp ($lang);
chomp ($title);
chomp ($pubInfo);
chomp ($ctry);
chomp ($pdate);
chomp ($note);
chomp ($reel);
my $REEL = qq {reel $reel};
# Begin constructing MARC records
my $record = MARC::Record->new();
my $leader = $record->leader();
substr($leader,5,3) = 'nam';
## Enc Lvl set to 3 abbreviated; descriptive set for unknown
substr($leader,17,2) = '3u';
$record->leader($leader);
# constructing MARC fields
$record->append_fields(
MARC::Field->new('003','SCL'),
MARC::Field->new('008', '061110s 000 0 fre d'),
MARC::Field->new('040','','','a', 'EYM', 'c', 'EYM'),
## adding 100
MARC::Field->new('100','1',' ','a', $author),
## adding 245
MARC::Field->new('245','1','0','a', $title),
## adding 260
MARC::Field->new('260',' ',' ','a',$pubInfo, 'c', $pdate),
## add note
MARC::Field->new('533','','','a', 'Microfilm.', 'n', $REEL),
MARC::Field->new('590','','','a', $note),
);
##fixing 1XX field
## recording 1XX field by the first 3-digit
my $f100 = $record->field('100');
my $f100a = $record->field('100')->subfield('a');
if ( $f100a =~ /^\d{3}/ ) {
my $tagField = substr($f100a, 0, 3);
my $IndField1 = substr($f100a, 3, 1);
my $SubA = substr($f100a, 5, );
## getting more subfields out of the 1XX string, $SubA,
## example:10000|a Henry |b II, |c King of France, |d 1519-1559
## example:1001 |a Grenaille, |c M. de |q (François), |c sieur de Chatounieres, |d 1616-168
##################### from B. Baldus 2006-11-01
#my $subfield_delimiter = '|';
my @subfields = split( / \|/, $SubA);
# Split the subfield data into subfield name and data pairs
my @subfield_data = ();
for ( @subfields ) {
if ( length > 0 ) {
#get code as 1st char, skip space, then rest for data
#print $_, "\n";
push( @subfield_data, substr($_,0,1), substr($_,2) );
} else {
print "Entirely empty subfield found in tag $tagField $SubA", "\n" ;
} #else empty subfield
} #for @subfields
if ( !@subfield_data ) {
print "no subfield data found $author for tag $tagField", "\n" ;
next;
} #if not subfield data
#####################
## put NEW 1XX field together
my $new1XX= MARC::Field->new( $tagField, $IndField1, '', @subfield_data);
$f100->replace_with($new1XX);
}
# print out records
print OUT $record->as_usmarc();
}