Assume we have a record with two 035 fields 035 -- $91234567 035 -- $a(XX)12345678
Now, this code will get the 035 $9 subfield: $subfield = eval { $record->field('035')->subfield('9') }; @subfields = eval { $record->field('035')->subfield('9') };
But this it will fail getting 035 $a $subfield = eval { $record->field('035')->subfield('a') }; @subfields = eval { $record->field('035')->subfield('a') };
I don't see how this can be. Am I missing something?
Paul.
-----Ursprungligt meddelande----- Från: Paul Hoffman [mailto:[EMAIL PROTECTED] Skickat: den 6 november 2003 22:30 Till: Leif Andersson Kopia: [EMAIL PROTECTED] Ämne: Re: Return values from MARC::Record
On Thursday, November 6, 2003, at 01:14 PM, Leif Andersson wrote:
With the same BAD record we try $subfield = eval {
$record->field($tag)->subfield($sub) }
This is the only case where we have to put the code in eval.
Should MARC:: take care of the eval for us? I am beginning to think so.
No, it can't. Just add your own error checking, something like this for example:
my $field = $record->field($tag) || die "No tag '$tag' in record"; $subfield = $field->subfield($sub);
MARC::Record::field has no way of knowing that your code will invoke the method 'subfield' on the value it returns. You could also do it like this if you want to keep things concise:
$subfield = ($record->field($tag) || die "No tag '$tag' in record")->subfield($sub);
But that's getting a wee bit obfuscated.
Paul.
-- Paul Hoffman :: Taubman Medical Library :: Univ. of Michigan [EMAIL PROTECTED] :: [EMAIL PROTECTED] :: http://www.nkuitse.com/