Re: Deleting a subfield using MARC::Record

[email protected] (Edward Summers)
Newsgroups perl.perl4lib
Message-ID <[email protected]>
On Apr 29, 2006, at 1:08 AM, Mark Jordan wrote:
> Edward Summers wrote:
>
>> Deleting subfields is a bit tricky since subfields may repeat, and  
>> sometimes people just want to delete one of them. An unfortunate  
>> state of affairs perhaps.
>
> Yeah, I can see what you're saying, but doesn't that also apply to  
> repeatable fields?

Well yeah it does, and you're right there is a  
MARC::Record::delete_field isn't there. Would having something  
similar to
that in MARC::Field be useful to you?

> If a particular subfield that is one of a repeated set needed to be  
> deleted, it could be identified by a regex or by its order in an  
> array (following object syntax probably not correct):
>
> @subfields = $subject->subfields();
> foreach $notwanted (@subfields) {
>   if ($notwanted =~ /badsubject/) {
>       $notwanted->delete_subfield();
>   }
> }

That could work if subfields were objects, but they're just strings.  
It could simply delete all of them unless a second parameter is  
passed in, which would basically act like a filter:

$field->delete_subfield('a', qr/badsubject/);

An alternative of course is to play fast and loose with the Object  
model and twiddle with $field->_subfields ... this is an array that  
looks like:

	['a', 'foo', 'b', 'bar']

Of course this opens you up to future failure if the internals of  
MARC::Field change at some point in the future. Which may not be all  
that likely :-)

//Ed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.