2 |
|
|
3 |
use strict; |
use strict; |
4 |
use Carp; |
use Carp; |
5 |
use Data::Dumper; |
use Data::Dump qw/dump/; |
6 |
|
|
7 |
BEGIN { |
BEGIN { |
8 |
use Exporter (); |
use Exporter (); |
88 |
|
|
89 |
if ($len < 24) { |
if ($len < 24) { |
90 |
carp "short read of leader, aborting\n"; |
carp "short read of leader, aborting\n"; |
91 |
|
$self->{count}--; |
92 |
last; |
last; |
93 |
} |
} |
94 |
|
|
125 |
|
|
126 |
# skip to next record |
# skip to next record |
127 |
my $o = substr($leader,0,5); |
my $o = substr($leader,0,5); |
128 |
|
warn "# in record ", $self->{count}," record length isn't number but: ",dump($o),"\n" unless $o =~ m/^\d+$/; |
129 |
if ($o > 24) { |
if ($o > 24) { |
130 |
seek($self->{fh},$o-24,1) if ($o); |
seek($self->{fh},$o-24,1) if ($o); |
131 |
} else { |
} else { |
338 |
|
|
339 |
# repeatable subfiled -- convert it to array |
# repeatable subfiled -- convert it to array |
340 |
if ($val->{$f}) { |
if ($val->{$f}) { |
341 |
if ( $sf_usage->{$f} == 2 ) { |
if ( ref($val->{$f}) ne 'ARRAY' ) { |
342 |
$val->{$f} = [ $val->{$f}, $val ]; |
$val->{$f} = [ $val->{$f}, $val ]; |
343 |
} else { |
} else { |
344 |
push @{$val->{$f}}, $val; |
push @{$val->{$f}}, $val; |
385 |
1; |
1; |
386 |
__END__ |
__END__ |
387 |
|
|
388 |
|
=head1 UTF-8 ENCODING |
389 |
|
|
390 |
|
This module does nothing with encoding. But, since MARC format is byte |
391 |
|
oriented even when using UTF-8 which has variable number of bytes for each |
392 |
|
character, file is opened in binary mode. |
393 |
|
|
394 |
|
As a result, all scalars recturned to perl don't have utf-8 flag. Solution is |
395 |
|
to use C<hash_filter> and L<Encode> to decode utf-8 encoding like this: |
396 |
|
|
397 |
|
use Encode; |
398 |
|
|
399 |
|
my $marc = new MARC::Fast( |
400 |
|
marcdb => 'utf8.marc', |
401 |
|
hash_filter => sub { |
402 |
|
Encode::decode( 'utf-8', $_[0] ); |
403 |
|
}, |
404 |
|
); |
405 |
|
|
406 |
|
This will affect C<to_hash>, but C<fetch> will still return binary representation |
407 |
|
since it doesn't support C<hash_filter>. |
408 |
|
|
409 |
=head1 AUTHOR |
=head1 AUTHOR |
410 |
|
|
411 |
Dobrica Pavlinusic |
Dobrica Pavlinusic |