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

[email protected] (Eric Lease Morgan) Thu, 13 Feb 2014 16:36:16 -0500
Newsgroups perl.perl4lib
Message-ID <[email protected]>
On Feb 13, 2014, at 4:20 PM, Anne Highsmith <[email protected]> wrot=
e:

> 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 =93blow up=94, do you mean it dies, quits, stops, exits, etc? =
Or do you mean it only throws an ugly error message? If the former, then yo=
u might wrap your processing an a (Perl) eval statement. A good example com=
es with the code for ZOOM, a Z39.50 interface:

 eval {
=20
     $conn =3D new ZOOM::Connection($host, $port, databaseName =3D> "mydb")=
;
     $conn->option(preferredRecordSyntax =3D> "usmarc");
     $rs =3D $conn->search_pqf('@attr 1=3D4 dinosaur');
     $n =3D $rs->size();
     print $rs->record(0)->render();
    =20
 };
=20
 if ( $@) { print "Error ", $@->code(), ": ", $@->message(), "\n=94 }

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.=20

HTH.=20

=97=20
Eric Lease Morgan