--- trunk/Fast.pm 2005/12/18 23:12:26 6 +++ trunk/Fast.pm 2007/06/18 22:54:02 14 @@ -1,5 +1,5 @@ - package MARC::Fast; + use strict; use Carp; use Data::Dumper; @@ -7,7 +7,7 @@ BEGIN { use Exporter (); use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); - $VERSION = 0.02; + $VERSION = 0.06; @ISA = qw (Exporter); #Give a hoot don't pollute, do not export more than needed by default @EXPORT = qw (); @@ -42,6 +42,11 @@ quiet => 0, debug => 0, assert => 0, + hash_filter => sub { + my ($t, $record_number) = @_; + $t =~ s/foo/bar/; + return $t; + }, ); =cut @@ -265,14 +270,14 @@ my $row = $self->fetch($mfn) || return; - foreach my $k (keys %{$row}) { - foreach my $l (@{$row->{$k}}) { + foreach my $rec_nr (keys %{$row}) { + foreach my $l (@{$row->{$rec_nr}}) { # remove end marker $l =~ s/\x1E$//; # filter output - $l = $self->{'hash_filter'}->($l) if ($self->{'hash_filter'}); + $l = $self->{'hash_filter'}->($l, $rec_nr) if ($self->{'hash_filter'}); my $val; @@ -283,30 +288,57 @@ if ($l =~ m/\x1F/) { foreach my $t (split(/\x1F/,$l)) { next if (! $t); + my $f = substr($t,0,1); + # repeatable subfileds. When we hit first one, + # store CURRENT (up to that) in first repetition + # of this record. Then, new record with same + # identifiers will be created. + if ($val->{$f}) { + push @{$rec->{$rec_nr}}, $val; + $val = { + i1 => $val->{i1}, + i2 => $val->{i2}, + }; + } $val->{substr($t,0,1)} = substr($t,1); } } else { $val = $l; } - push @{$rec->{$k}}, $val; + push @{$rec->{$rec_nr}}, $val; } } return $rec; } +=head2 to_ascii -1; -__END__ + print $marc->to_ascii( 42 ); + +=cut -=head1 BUGS +sub to_ascii { + my $self = shift; + my $mfn = shift || confess "need mfn"; + my $row = $self->fetch($mfn) || return; + my $out; -=head1 SUPPORT + foreach my $f (sort keys %{$row}) { + my $dump = join('', @{ $row->{$f} }); + $dump =~ s/\x1e$//; + $dump =~ s/\x1f/\$/g; + $out .= "$f\t$dump\n"; + } + return $out; +} +1; +__END__ =head1 AUTHOR @@ -326,6 +358,6 @@ =head1 SEE ALSO -perl(1). +L, perl(1). =cut