On Feb 13, 2014, at 4:20 PM, Anne Highsmith <hism...@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. 


Eric Lease Morgan

Reply via email to