Re: Deleting a subfield using MARC::Record
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
Re: Deleting a subfield using MARC::Record
Edward Summers wrote: 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/); That sounds pretty good, though I'm working with a database where I found a 6xx field with two identical occurrences of subfield 2. So what you propose would, I suppose, delete both of them and I'd have to put one back in. Add another parameter to specify which occurrence? Mike
Re: Deleting a subfield using MARC::Record
Edward Summers wrote: 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? Strangely enough, I've encountered two separate situations in the last two weeks (both on Friday afternoons... I think I've fallen into some kind of recursive metadata loop) where I wanted to delete just a specific subfield. Maybe other people should verify the usefulness of a delete subfield function before anyone does anything about it, though. Would a half dozen +1 votes from perl4libers validate its usefulness? 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/); Yeah, I knew I had the syntax wrong. The revised one you supply looks intuitive. Could the second parameter also accommodate the order (in an array) of the target subfield if the subfield repeated, for when you know your records are consistent enough to use it (such as when you get vendor records that have two 856 u subfields but you only want the second one)? For example: $field->delete_subfield('a', 0); Mark