193 |
# first, sort all existing fields |
# first, sort all existing fields |
194 |
# XXX might not be needed, but modern perl might randomize elements in hash |
# XXX might not be needed, but modern perl might randomize elements in hash |
195 |
my @sorted_marc_record = sort { |
my @sorted_marc_record = sort { |
196 |
$a->[0] . $a->[3] cmp $b->[0] . $b->[3] |
$a->[0] . ( $a->[3] || '' ) cmp $b->[0] . ( $b->[3] || '') |
197 |
} @{ $marc_record }; |
} @{ $marc_record }; |
198 |
|
|
199 |
@sorted_marc_record = @{ $marc_record }; ### FIXME disable sorting |
@sorted_marc_record = @{ $marc_record }; ### FIXME disable sorting |
203 |
|
|
204 |
# count unique field-subfields (used for offset when walking to next subfield) |
# count unique field-subfields (used for offset when walking to next subfield) |
205 |
my $u; |
my $u; |
206 |
map { $u->{ $_->[0] . $_->[3] }++ } @sorted_marc_record; |
map { $u->{ $_->[0] . ( $_->[3] || '') }++ } @sorted_marc_record; |
207 |
|
|
208 |
if ($debug) { |
if ($debug) { |
209 |
warn "## marc_repeatable_subfield ", dump( $marc_repeatable_subfield ), $/; |
warn "## marc_repeatable_subfield ", dump( $marc_repeatable_subfield ), $/; |
231 |
|
|
232 |
# field and subfield which is key for |
# field and subfield which is key for |
233 |
# marc_repeatable_subfield and u |
# marc_repeatable_subfield and u |
234 |
my $fsf = $row->[0] . $row->[3]; |
my $fsf = $row->[0] . ( $row->[3] || '' ); |
235 |
|
|
236 |
if ($debug > 1) { |
if ($debug > 1) { |
237 |
|
|
381 |
Save value for MARC field |
Save value for MARC field |
382 |
|
|
383 |
marc('900','a', rec('200','a') ); |
marc('900','a', rec('200','a') ); |
384 |
|
marc('001', rec('000') ); |
385 |
|
|
386 |
=cut |
=cut |
387 |
|
|
389 |
my $f = shift or die "marc needs field"; |
my $f = shift or die "marc needs field"; |
390 |
die "marc field must be numer" unless ($f =~ /^\d+$/); |
die "marc field must be numer" unless ($f =~ /^\d+$/); |
391 |
|
|
392 |
my $sf = shift or die "marc needs subfield"; |
my $sf; |
393 |
|
if ($f >= 10) { |
394 |
|
$sf = shift or die "marc needs subfield"; |
395 |
|
} |
396 |
|
|
397 |
foreach (@_) { |
foreach (@_) { |
398 |
my $v = $_; # make var read-write for Encode |
my $v = $_; # make var read-write for Encode |
399 |
next unless (defined($v) && $v !~ /^\s*$/); |
next unless (defined($v) && $v !~ /^\s*$/); |
400 |
from_to($v, 'iso-8859-2', $marc_encoding) if ($marc_encoding); |
from_to($v, 'iso-8859-2', $marc_encoding) if ($marc_encoding); |
401 |
my ($i1,$i2) = defined($marc_indicators->{$f}) ? @{ $marc_indicators->{$f} } : (' ',' '); |
my ($i1,$i2) = defined($marc_indicators->{$f}) ? @{ $marc_indicators->{$f} } : (' ',' '); |
402 |
push @{ $marc_record }, [ $f, $i1, $i2, $sf => $v ]; |
if (defined $sf) { |
403 |
|
push @{ $marc_record }, [ $f, $i1, $i2, $sf => $v ]; |
404 |
|
} else { |
405 |
|
push @{ $marc_record }, [ $f, $v ]; |
406 |
|
} |
407 |
} |
} |
408 |
} |
} |
409 |
|
|
496 |
|
|
497 |
sub rec1 { |
sub rec1 { |
498 |
my $f = shift; |
my $f = shift; |
499 |
|
warn "rec1($f) = ", dump( $rec->{$f} ), $/ if ($debug > 1); |
500 |
return unless (defined($rec) && defined($rec->{$f})); |
return unless (defined($rec) && defined($rec->{$f})); |
501 |
|
warn "rec1($f) = ", dump( $rec->{$f} ), $/ if ($debug > 1); |
502 |
if (ref($rec->{$f}) eq 'ARRAY') { |
if (ref($rec->{$f}) eq 'ARRAY') { |
503 |
return map { |
return map { |
504 |
if (ref($_) eq 'HASH') { |
if (ref($_) eq 'HASH') { |
681 |
if ($part && $part > 0) { |
if ($part && $part > 0) { |
682 |
return $s[ $part - 1 ]; |
return $s[ $part - 1 ]; |
683 |
} else { |
} else { |
684 |
return [ @s ]; |
return @s; |
685 |
} |
} |
686 |
} |
} |
687 |
|
|