X-Git-Url: http://git.rot13.org/?p=MARC-Fast;a=blobdiff_plain;f=Fast.pm;h=dea7a9104fb5fd8c7f7b6ffc46f8ed4de1ac33e3;hp=aa510ba5ab60b9f2bdb583de5d95bcecf9b5e8aa;hb=df7293d3cca255a7a43c0e78606fd113c8970725;hpb=1677866871d5303a178499e33f86e3c02af57877 diff --git a/Fast.pm b/Fast.pm index aa510ba..dea7a91 100644 --- a/Fast.pm +++ b/Fast.pm @@ -2,7 +2,7 @@ package MARC::Fast; use strict; use Carp; -use Data::Dumper; +use Data::Dump qw/dump/; BEGIN { use Exporter (); @@ -88,6 +88,7 @@ sub new { if ($len < 24) { carp "short read of leader, aborting\n"; + $self->{count}--; last; } @@ -124,6 +125,7 @@ sub new { # skip to next record my $o = substr($leader,0,5); + warn "# in record ", $self->{count}," record length isn't number but: ",dump($o),"\n" unless $o =~ m/^\d+$/; if ($o > 24) { seek($self->{fh},$o-24,1) if ($o); } else { @@ -336,7 +338,7 @@ sub to_hash { # repeatable subfiled -- convert it to array if ($val->{$f}) { - if ( $sf_usage->{$f} == 2 ) { + if ( ref($val->{$f}) ne 'ARRAY' ) { $val->{$f} = [ $val->{$f}, $val ]; } else { push @{$val->{$f}}, $val; @@ -383,6 +385,27 @@ sub to_ascii { 1; __END__ +=head1 UTF-8 ENCODING + +This module does nothing with encoding. But, since MARC format is byte +oriented even when using UTF-8 which has variable number of bytes for each +character, file is opened in binary mode. + +As a result, all scalars recturned to perl don't have utf-8 flag. Solution is +to use C and L to decode utf-8 encoding like this: + + use Encode; + + my $marc = new MARC::Fast( + marcdb => 'utf8.marc', + hash_filter => sub { + Encode::decode( 'utf-8', $_[0] ); + }, + ); + +This will affect C, but C will still return binary representation +since it doesn't support C. + =head1 AUTHOR Dobrica Pavlinusic