--- trunk/lib/WebPAC/Normalize.pm 2007/04/01 21:47:48 814 +++ trunk/lib/WebPAC/Normalize.pm 2007/04/02 17:20:01 815 @@ -9,7 +9,7 @@ tag search display marc marc_indicators marc_repeatable_subfield - marc_compose marc_leader + marc_compose marc_leader marc_fixed marc_duplicate marc_remove marc_count marc_original_order @@ -42,11 +42,11 @@ =head1 VERSION -Version 0.27 +Version 0.28 =cut -our $VERSION = '0.27'; +our $VERSION = '0.28'; =head1 SYNOPSIS @@ -517,6 +517,47 @@ } } +=head2 marc_fixed + +Create control/indentifier fields with values in fixed positions + + marc_fixed('008', 00, '070402'); + marc_fixed('008', 39, '|'); + +Positions not specified will be filled with spaces (C<0x20>). + +There will be no effort to extend last specified value to full length of +field in standard. + +=cut + +sub marc_fixed { + my ($f, $pos, $val) = @_; + die "need marc(field, position, value)" unless defined($f) && defined($pos); + + my $update = 0; + + map { + if ($_->[0] eq $f) { + my $old = $_->[1]; + if (length($old) < $pos) { + $_->[1] .= ' ' x ( $pos - length($old) ) . $val; + warn "## marc_fixed($f,$pos,'$val') append '$old' -> '$_->[1]'\n"; + } else { + $_->[1] = substr($old, 0, $pos) . $val . substr($old, $pos + length($val)); + warn "## marc_fixed($f,$pos,'$val') update '$old' -> '$_->[1]'\n"; + } + $update++; + } + } @{ $marc_record->[ $marc_record_offset ] }; + + if (! $update) { + my $v = ' ' x $pos . $val; + push @{ $marc_record->[ $marc_record_offset ] }, [ $f, $v ]; + warn "## marc_fixed($f,$pos,'val') created '$v'\n"; + } +} + =head2 marc Save value for MARC field