Skip to content

Commit

Permalink
Adding an example how to add subfields to a MARC field #68
Browse files Browse the repository at this point in the history
  • Loading branch information
phochste committed Jun 21, 2018
1 parent ab2325c commit 77d75f6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/Catmandu/Fix/Bind/marc_each.pm
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ MARC fields.
if all_match(this.tag,500)
set_field(tag.ind1,3)
# Store the result in the MARC file
marc_remove(500)
marc_paste(this)
end
end
Expand Down
1 change: 0 additions & 1 deletion lib/Catmandu/Fix/marc_cut.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ has equals => (fix_opt => 1);
sub emit {
my ($self,$fixer) = @_;
my $path = $fixer->split_path($self->path);
my $key = $path->[-1];
my $marc_obj = Catmandu::MARC->instance;

# Precompile the marc_path to gain some speed
Expand Down
18 changes: 18 additions & 0 deletions lib/Catmandu/MARC/Tutorial.pod
Original file line number Diff line number Diff line change
Expand Up @@ -426,13 +426,31 @@ We will use the L<Catmandu::Fix::Bind::marc_each> bind with a loop variable:
# Set the indicator1 to value "0"
set_field(this.ind1,0)
# Store the result back into the MARC record
marc_remove(500)
marc_paste(this)
end
end

Using the same method indicators can also be deleted by setting their value to
a space " ".

=head2 Adding a new MARC subfield

In the example below we append a new MARC subfield $z to the 500 field with value test.
We will use the L<Catmandu::Fix::Bind::marc_each> bind with a loop variable:

# For each marc field...
do marc_each(var:this)
# If the marc field is a 500 field
if marc_has(500)
# add a new subfield z
add_field(this.subfields.$append.z,Test)
# Store the result back into the MARC record
marc_remove(500)
marc_paste(this)
end
end

=head1 WRITING

=head2 Convert a MARC record into a MARC record (do nothing)
Expand Down

0 comments on commit 77d75f6

Please sign in to comment.