# If the target record has multiple matching bib fields,
# replace them from matching fields on the source record
# in a predictable order to avoid replacing with them with
- # same source field repeatedly.
- my $source_field = ($source_r->field($f))[++$tag_idx];
+ # same source field repeatedly. However, if there are more
+ # target fields than source fields, use the last available
+ # source field as the input for all remaining target fields.
+ # TODO: there may be cases where we do not want a single
+ # source field to affect multiple target fields. It works
+ # well when replacing multiple bib 700a values with a single
+ # 100a authority record value, but maybe not when overlaying
+ # one bib record onto another. Should this be flag/setting?
+ my @source_fields = $source_r->field($f);
+ my $source_field = $source_fields[++$tag_idx]
+ || $source_fields[$#source_fields];
if (!$source_field) {
# No source field exists. Delete all affected target