[librecat-dev] string operations, defining functions in Catmandu

Uldis Bojars captsolo at gmail.com
Thu Jun 29 15:49:18 CEST 2017


On 29 June 2017 at 14:28, Patrick Hochstenbach <
Patrick.Hochstenbach at ugent.be> wrote:

>
> But while waiting for this new feature you can use a dirty trick to get
> the required result. The Fix script below will add the 100 subfields to the
> 400 field and adds a
> period “.” when required:
>
> [...]
>
> The trick is the append(record.$last.$last,".”) line which knows that MARC
> is modeled as an array of arrays in Catmandu and adds a period to the last
> element.
>

Thanks! This trick + "marc_match(100aqbcd,"\.$")" saves the day :)

What if I need to reuse the result [ = the new field 400aqbcd with "." at
the end ] multiple times (e.g. to create multiple 400 fields with more
subfields added, different in each case)?

Is there a way to copy the full structure (with subfields) of a MARC field
into a temporary field / variable and then create a new MARC field based on
it?
  - another option is to hold this temporary value in a non-standard MARC
field (e.g. "XYZ") but that feels like a hack

P.S. Is there a way to dump / log contents of a field (variable) from the
Fix script?

Uldis


> On 28 Jun 2017, at 18:41, Uldis Bojars <captsolo at gmail.com> wrote:
> >
> > Hi,
> >
> > Could you suggest how to do this in Catmandu:
> >
> > I need to form a new MARC field ("400") that consist of some subfields
> (in this order: $a $q $b $c $d) of an existing field ("100"). That much is
> not difficult, but there's another condition:
> >
> > "." must be added to the last subfield that exists (e.g. if $d exists
> append "." to it unless it already ends with ".", otherwise do the same
> with $c, [...]) .
> >
> > Questions:
> >
> > 1) how to determine if a field (e.g. fld_100d created via marc_map) ends
> with "." ?
> >
> > 2) is there a way to "package" some functionality and call it when
> needed?
> >
> > In this case it would be good to create a function that appends "." to
> the field provided as a parameter unless it already ends with ".".
> >
> > Then what is needed could be achieved like this:
> >
> > if exists("fld_100d"):
> >    my_function("fld_100d")
> > elsif exists("fld_100c"):
> >    my_function("fld_100c")
> > elsif [...]
> >    [...]
> > end
> >
> > P.S. Perhaps there is a more idiomatic way how to do this in Catmandu?
> >
> > Thanks,
> > Uldis
> >
> > _______________________________________________
> > librecat-dev mailing list
> > - send list mails to librecat-dev at lists.uni-bielefeld.de
> > - to unsubscribe or change options, visit https://lists.uni-bielefeld.
> de/mailman2/cgi/unibi/listinfo/librecat-dev
> > - project website: http://librecat.org/
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.uni-bielefeld.de/mailman2/unibi/public/librecat-dev/attachments/20170629/98d42b6f/attachment.html>


More information about the librecat-dev mailing list