[libcatmandu-marc-perl] 15/26: Adding an example how to lookup tags in a CSV file
Jonas Smedegaard
dr at jones.dk
Tue Dec 19 12:17:04 UTC 2017
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag upstream/1.23.1
in repository libcatmandu-marc-perl.
commit f6b65a3d89ba72a6ed451f30da25a6b6c774f1cb
Author: Patrick Hochstenbach <patrick.hochstenbach at ugent.be>
Date: Wed Dec 6 16:05:28 2017 +0100
Adding an example how to lookup tags in a CSV file
---
lib/Catmandu/MARC/Tutorial.pod | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/lib/Catmandu/MARC/Tutorial.pod b/lib/Catmandu/MARC/Tutorial.pod
index 75c20ec..cf4b1fc 100644
--- a/lib/Catmandu/MARC/Tutorial.pod
+++ b/lib/Catmandu/MARC/Tutorial.pod
@@ -435,3 +435,34 @@ back the C<tmp> field into the record.
=head2 Select only the records with 900a == book
$ catmandu convert MARC to MARC --fix 'marc_map(900a,type); select all_match(type,book)' < data.mrc > output.mrc
+
+The C<all_match> also allows a regular expressions:
+
+ $ catmandu convert MARC to MARC --fix 'marc_map(900a,type); select all_match(type,"[Bb]ook")' < data.mrc > output.mrc
+
+=head2 Select only the rcords with 900a values in a given CSV file
+
+Create a CSV file with name,value pairs (need two columns):
+
+ $ cat values.csv
+ name,values
+ book,1
+ journal,1
+ movie,1
+
+ $ catmandu convert MARC to MARC --fix myfixes.txt < data.mrc > output.mrc
+
+ with myfixes.txt like:
+
+ do marc_each()
+ marc_map(900a,test)
+ lookup(test,values.csv,default:0)
+ select all_match(test,1)
+ remove_field(test)
+ end
+
+We use a "do marc_each() ... end" loop because 900a fields can be repeated. If a
+MARC tag isn't repeatable this loop not isn't needed. With marc_map we copy
+first the value of a marc subfield to a 'test' field. This test we lookup against
+the CSV file. Then, we select only the records that are found in the CSV file
+(and return the correct value).
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libcatmandu-marc-perl.git
More information about the Pkg-perl-cvs-commits
mailing list