- @f = ( $1, $2, $3 );
- sub sf { push @f, @_; }
- $line =~ s{<s>(\w)<e>([^<]+)\s*}{sf($1, $2)}ges;
- diag "# f:", join('|', @f), " left: |$line|";
- $marc->add_fields( @f );
+ my ( $f, $i1, $i2 ) = ( $1, $2, $3 );
+
+ our $marc_map = undef;
+ our $comarc_map = undef;
+ our $ignored = undef;
+
+ sub sf_parse {
+ my ($f,$sf,$v) = @_;
+
+ $v =~ s/\s+$//;
+
+ push @{ $comarc_map->{ $f } }, ( $sf, $v );
+ if ( my $m = $cobiss_marc21->{$f}->{$sf} ) {
+ push @{ $marc_map->{ $m->[0] } }, ( $m->[1], $v );
+ } else {
+ $ignored->{$f}++;
+ }
+ return ''; # fix warning
+ }
+ my $l = $line;
+ $l =~ s{<s>(\w)<e>([^<]+)}{sf_parse($f,$1, $2)}ges;
+
+ diag "[$format] $line -> ",dump( $comarc_map, $marc_map ) if $comarc_map;
+
+ foreach my $f ( keys %$comarc_map ) {
+ $comarc->add_fields( $f, $i1, $i2, @{ $comarc_map->{$f} } );
+ }
+
+ foreach my $f ( keys %$marc_map ) {
+ $marc->add_fields( $f, $i1, $i2, @{ $marc_map->{$f} } );
+ }