fix repeatable subfields in to_hash
authorDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 23 Sep 2010 13:07:28 +0000 (13:07 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 23 Sep 2010 13:07:28 +0000 (13:07 +0000)
git-svn-id: svn+ssh://llin/home/dpavlin/private/svn/MARC-Fast/trunk@42 49f9634a-d7ec-0310-8e6b-ec35c6cc8804

lib/MARC/Fast.pm

index aef3d5b..35a1e6a 100644 (file)
@@ -333,18 +333,20 @@ sub to_hash {
                                foreach my $t (split(/\x1F/,$l)) {
                                        next if (! $t);
                                        my $f = substr($t,0,1);
+                                       my $v = substr($t,1);
 
                                        push @subfields, ( $f, $sf_usage->{$f}++ || 0 );
 
                                        # repeatable subfiled -- convert it to array
-                                       if ($val->{$f}) {
+                                       if ( defined $val->{$f} ) {
                                                if ( ref($val->{$f}) ne 'ARRAY' ) {
-                                                       $val->{$f} = [ $val->{$f}, $val ];
+                                                       $val->{$f} = [ $val->{$f}, $v ];
                                                } else {
-                                                       push @{$val->{$f}}, $val;
+                                                       push @{$val->{$f}}, $v;
                                                }
+                                       } else {
+                                               $val->{$f} = $v;
                                        }
-                                       $val->{substr($t,0,1)} = substr($t,1);
                                }
                                $val->{subfields} = [ @subfields ] if $args->{include_subfields};
                        } else {