I am cleaning up a number of MARC records, and would like to remove any
extra spaces at the end of the last subfield in each field > 010 (since the
010 has special spacing requirements). Would code similar to that below do
what I want?

(based on tutorial example 18 (v. 1.32), with it's code up to line 9):
#$tagnumber is defined somewhere else
my $existing = $record->field($tagnumber);

@arrayofsubfields = $existing->subfields();
##This probably isn't quite right:
@lastsubfield = pop @arrayofsubfields[0];
$lastsubfield[1] =~ s/\s+$/;
push @lastsubfield, @arrayofsubfields[0];

my $new = MARC::Field->new($tagnumber, $existing->indicator(1),
$existing->indicator(2), @arrayofsubfields);
$existing->replace_with($new);

print OUT $record->as_usmarc();

Thank you for your assistance,

Bryan Baldus
Cataloger
Quality Books, Inc.
The Best of America's Independent Presses
[EMAIL PROTECTED]

Reply via email to