Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Basic questions -- skipping records that don't pass muster

4 views
Skip to first unread message

Anne Highsmith

unread,
Feb 13, 2014, 4:20:11 PM2/13/14
to perl4lib
Through various programs, when I've been processing MARC records and found 1 that didn't pass muster (couldn't pass structural or character set requirements) I generally slogged through, found it, and fixed it. But now I have passed on some of my code to someone who doesn't have the time or the expertise to do that, so I'm asking for help on behalf of both of us.

First, let's say I have a hash of record id numbers (voyager bib ids for those who speak voyager) And here's a code snippet:

foreach my $bib (sort keys %list_of_docs_bibs) {
# put the bits of the marc record back into a string marc string
my $bib_marc = &get_bib_string($dbh, $dbase, $bib);
# create a marc record object from marc record string
my $bib_rec = MARC::Record->new_from_usmarc($bib_marc);

#do useful stuff to $bib_rec
}

Occasionally, this code will hit a bib record that has an invalid tag and will blow up with something like:
" Tag "`1`" is not a valid tag at ...USMARC.pm line 222"
What is an appropriate way to print out that record to an error file and go on to the next record, rather than having the program blow up and stop?
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Second, related question. Although all of the records in the voyager database are SUPPOSED to be in Unicode, one occasionally encounters a record that has non-Unicode characters. So, pretty much same question -- What is an appropriate way to print out that record someplace and go on to the next record, rather than having the program blow up and stop?

Suggestions gratefully appreciated

Anne L. Highsmith
Director of Consortia Systems
Texas A&M University
5000 TAMU
College Station, TX 77843-5000
Phone: 979 862 4234
Fax: 979 845 6238
Email: his...@tamu.edu

Eric Lease Morgan

unread,
Feb 13, 2014, 4:36:16 PM2/13/14
to perl4lib

On Feb 13, 2014, at 4:20 PM, Anne Highsmith <his...@library.tamu.edu> wrote:

> Occasionally, this code will hit a bib record that has an invalid tag and will blow up with something like:
> " Tag "`1`" is not a valid tag at ...USMARC.pm line 222"
> What is an appropriate way to print out that record to an error file and go on to the next record, rather than having the program blow up and stop?


When you say “blow up”, do you mean it dies, quits, stops, exits, etc? Or do you mean it only throws an ugly error message? If the former, then you might wrap your processing an a (Perl) eval statement. A good example comes with the code for ZOOM, a Z39.50 interface:

eval {

$conn = new ZOOM::Connection($host, $port, databaseName => "mydb");
$conn->option(preferredRecordSyntax => "usmarc");
$rs = $conn->search_pqf('@attr 1=4 dinosaur');
$n = $rs->size();
print $rs->record(0)->render();

};

if ( $@) { print "Error ", $@->code(), ": ", $@->message(), "\n” }

In this case the code inside the eval block gets executed, but if it fails (dies), then the error is trapped, sent to STDOUT, and processing continues.

In your case you might have loop through your records, and inside the loop you can put the eval block. If the block dies, then the loop will continue to the next record.

HTH.


Eric Lease Morgan


0 new messages