--- trunk/lib/WebPAC/Normalize.pm 2006/07/02 20:33:13 565 +++ trunk/lib/WebPAC/Normalize.pm 2006/07/03 14:32:40 572 @@ -193,7 +193,7 @@ # first, sort all existing fields # XXX might not be needed, but modern perl might randomize elements in hash my @sorted_marc_record = sort { - $a->[0] . $a->[3] cmp $b->[0] . $b->[3] + $a->[0] . ( $a->[3] || '' ) cmp $b->[0] . ( $b->[3] || '') } @{ $marc_record }; @sorted_marc_record = @{ $marc_record }; ### FIXME disable sorting @@ -203,7 +203,7 @@ # count unique field-subfields (used for offset when walking to next subfield) my $u; - map { $u->{ $_->[0] . $_->[3] }++ } @sorted_marc_record; + map { $u->{ $_->[0] . ( $_->[3] || '') }++ } @sorted_marc_record; if ($debug) { warn "## marc_repeatable_subfield ", dump( $marc_repeatable_subfield ), $/; @@ -231,7 +231,7 @@ # field and subfield which is key for # marc_repeatable_subfield and u - my $fsf = $row->[0] . $row->[3]; + my $fsf = $row->[0] . ( $row->[3] || '' ); if ($debug > 1) { @@ -299,7 +299,7 @@ sub _debug { my $l = shift; return $debug unless defined($l); - warn "debug level $l" if ($l > 0); + warn "debug level $l",$/ if ($l > 0); $debug = $l; } @@ -381,6 +381,7 @@ Save value for MARC field marc('900','a', rec('200','a') ); + marc('001', rec('000') ); =cut @@ -388,14 +389,21 @@ my $f = shift or die "marc needs field"; die "marc field must be numer" unless ($f =~ /^\d+$/); - my $sf = shift or die "marc needs subfield"; + my $sf; + if ($f >= 10) { + $sf = shift or die "marc needs subfield"; + } foreach (@_) { my $v = $_; # make var read-write for Encode next unless (defined($v) && $v !~ /^\s*$/); from_to($v, 'iso-8859-2', $marc_encoding) if ($marc_encoding); my ($i1,$i2) = defined($marc_indicators->{$f}) ? @{ $marc_indicators->{$f} } : (' ',' '); - push @{ $marc_record }, [ $f, $i1, $i2, $sf => $v ]; + if (defined $sf) { + push @{ $marc_record }, [ $f, $i1, $i2, $sf => $v ]; + } else { + push @{ $marc_record }, [ $f, $v ]; + } } } @@ -462,10 +470,10 @@ next unless (defined($v) && $v !~ /^\s*$/); from_to($v, 'iso-8859-2', $marc_encoding) if ($marc_encoding); push @$m, ( $sf, $v ); - warn "## ++ marc_compose($f,$sf,$v) ", dump( $m ) if ($debug > 1); + warn "## ++ marc_compose($f,$sf,$v) ", dump( $m ),$/ if ($debug > 1); } - warn "## marc_compose(d) ", dump( $m ) if ($debug > 1); + warn "## marc_compose(d) ", dump( $m ),$/ if ($debug > 1); push @{ $marc_record }, $m if ($#{$m} > 2); } @@ -488,7 +496,9 @@ sub rec1 { my $f = shift; + warn "rec1($f) = ", dump( $rec->{$f} ), $/ if ($debug > 1); return unless (defined($rec) && defined($rec->{$f})); + warn "rec1($f) = ", dump( $rec->{$f} ), $/ if ($debug > 1); if (ref($rec->{$f}) eq 'ARRAY') { return map { if (ref($_) eq 'HASH') { @@ -658,15 +668,17 @@ die "split_rec_on need (fld,sf,regex[,part]" if ($#_ < 2); my ($fld, $sf, $regex, $part) = @_; - warn "### regex ", ref($regex), $regex if ($debug > 2); + warn "### regex ", ref($regex), $regex, $/ if ($debug > 2); my @r = rec( $fld, $sf ); my $v = shift @r; - warn "### first rec($fld,$sf) = ",dump($v) if ($debug > 2); + warn "### first rec($fld,$sf) = ",dump($v),$/ if ($debug > 2); + + return '' if( ! defined($v) || $v =~ /^\s*$/); my @s = split( $regex, $v ); - warn "## split_rec_on($fld,$sf,$regex,$part) = ",dump(@s) if ($debug > 1); - if ($part > 0) { + warn "## split_rec_on($fld,$sf,$regex,$part) = ",dump(@s),$/ if ($debug > 1); + if ($part && $part > 0) { return $s[ $part - 1 ]; } else { return @s;