--- trunk/Fast.pm 2010/02/04 17:15:09 35 +++ trunk/lib/MARC/Fast.pm 2013/08/22 11:24:36 47 @@ -7,7 +7,7 @@ BEGIN { use Exporter (); use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); - $VERSION = 0.10; + $VERSION = 0.12; @ISA = qw (Exporter); #Give a hoot don't pollute, do not export more than needed by default @EXPORT = qw (); @@ -277,11 +277,14 @@ Read record with specified MFN and convert it to hash - my $hash = $marc->to_hash( $mfn, include_subfields => 1, ); + my $hash = $marc->to_hash( $mfn, include_subfields => 1, + hash_filter => sub { my ($l,$tag) = @_; return $l; } + ); It has ability to convert characters (using C) from MARC database before creating structures enabling character re-mapping or quick -fix-up of data. +fix-up of data. If you specified C both in C and C +only the one from C will be used. This function returns hash which is like this: @@ -305,20 +308,21 @@ my $mfn = shift || confess "need mfn!"; my $args = {@_}; + my $filter_coderef = $args->{'hash_filter'} || $self->{'hash_filter'}; # init record to include MFN as field 000 my $rec = { '000' => [ $mfn ] }; my $row = $self->fetch($mfn) || return; - foreach my $rec_nr (keys %{$row}) { - foreach my $l (@{$row->{$rec_nr}}) { + foreach my $tag (keys %{$row}) { + foreach my $l (@{$row->{$tag}}) { # remove end marker $l =~ s/\x1E$//; # filter output - $l = $self->{'hash_filter'}->($l, $rec_nr) if ($self->{'hash_filter'}); + $l = $filter_coderef->($l, $tag) if $filter_coderef; my $val; @@ -333,25 +337,27 @@ 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 { $val = $l; } - push @{$rec->{$rec_nr}}, $val; + push @{$rec->{$tag}}, $val; } }