Re: Deleting a subfield using MARC::Record

[email protected] (Edward Summers)
Newsgroups perl.perl4lib
Message-ID <[email protected]>
On May 1, 2006, at 4:41 PM, Leif Andersson wrote:

> +1
>
> "count" can possibly be complemented or replaced with occurrence as  
> suggested.
> It'd be nice to be able to denote last occurrence [-1].
> And I suppose the indexing should be based on ordinary perl  
> subscript indexing - i.e. governed by the value of special variable $[
>
> $field->delete_subfield( code => $code,      # of course
>                          occur => [0,2,3],   # "occur" or "pos" or  
> whatever...
>                          match => qr/pat/,   # doesn't need to be  
> repeatable
>                        );

I actually like 'pos' better than 'occur' -- but alas

	$field->delete_subfield(pos => 2);

won't work because 'pos' is a perl keyword--which is why I like using  
it I suppose :-) How about:

	$field->delete_subfield(position => 2);

A bit more wordy I guess, but I still like it better than occur. Nice  
tip on the use of $[ by the way! I also like Tim's suggestion to  
allow 'code' to take multiple values too:

	$field->delete_subfield(code => ['a','b','c'])

So if you check out the CVS you should find this implemented. If you  
are interested in adding any tests or documentation let me know and  
I'll add you as a sf.net developer.

The current documentation for the new method reads like this:

--

        delete_subfield() allows you to remove subfields from a field:

            # delete any subfield a in the field
            $field->delete_subfield(code => 'a');

            # delete any subfield a or u in the field
            $field->delete_subfield(code => ['a', 'u']);

        If you want to only delete subfields at a particular position  
you can
        use the position parameter:

            # delete subfield u at the first position
            $field->delete_subfield(code => 'u', position => 0);

            # delete subfield u at first or second position
            $field->delete_subfield(code => 'u', position => [0,1]);

        You can specify a regex to for only deleting subfields that  
match:

           # delete any subfield u that matches zombo.com
           $field->delete_subfield(code => 'u', match => qr/zombo.com/);

--

Sound ok?

//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.