/[MARC-Fast]/trunk/lib/MARC/Fast.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/MARC/Fast.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 18 by dpavlin, Mon Oct 29 22:33:35 2007 UTC revision 26 by dpavlin, Mon Nov 19 16:37:00 2007 UTC
# Line 2  package MARC::Fast; Line 2  package MARC::Fast;
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 ();
9          use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);          use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
10          $VERSION     = 0.08;          $VERSION     = 0.09;
11          @ISA         = qw (Exporter);          @ISA         = qw (Exporter);
12          #Give a hoot don't pollute, do not export more than needed by default          #Give a hoot don't pollute, do not export more than needed by default
13          @EXPORT      = qw ();          @EXPORT      = qw ();
# Line 124  sub new { Line 124  sub new {
124    
125                  # skip to next record                  # skip to next record
126                  my $o = substr($leader,0,5);                  my $o = substr($leader,0,5);
127                    warn "# in record ", $self->{count}," record length isn't number but: ",dump($o),"\n" unless $o =~ m/^\d+$/;
128                  if ($o > 24) {                  if ($o > 24) {
129                          seek($self->{fh},$o-24,1) if ($o);                          seek($self->{fh},$o-24,1) if ($o);
130                  } else {                  } else {
# Line 275  sub last_leader { Line 276  sub last_leader {
276    
277  Read record with specified MFN and convert it to hash  Read record with specified MFN and convert it to hash
278    
279    my $hash = $marc->to_hash($mfn);    my $hash = $marc->to_hash( $mfn, include_subfields => 1, );
280    
281  It has ability to convert characters (using C<hash_filter>) from MARC  It has ability to convert characters (using C<hash_filter>) from MARC
282  database before creating structures enabling character re-mapping or quick  database before creating structures enabling character re-mapping or quick
# Line 302  sub to_hash { Line 303  sub to_hash {
303    
304          my $mfn = shift || confess "need mfn!";          my $mfn = shift || confess "need mfn!";
305    
306            my $args = {@_};
307    
308          # init record to include MFN as field 000          # init record to include MFN as field 000
309          my $rec = { '000' => [ $mfn ] };          my $rec = { '000' => [ $mfn ] };
310    
# Line 321  sub to_hash { Line 324  sub to_hash {
324                          # has identifiers?                          # has identifiers?
325                          ($val->{'i1'},$val->{'i2'}) = ($1,$2) if ($l =~ s/^([01 #])([01 #])\x1F/\x1F/);                          ($val->{'i1'},$val->{'i2'}) = ($1,$2) if ($l =~ s/^([01 #])([01 #])\x1F/\x1F/);
326    
327                            my $sf_usage;
328                            my @subfields;
329    
330                          # has subfields?                          # has subfields?
331                          if ($l =~ m/\x1F/) {                          if ($l =~ m/\x1F/) {
332                                  foreach my $t (split(/\x1F/,$l)) {                                  foreach my $t (split(/\x1F/,$l)) {
333                                          next if (! $t);                                          next if (! $t);
334                                          my $f = substr($t,0,1);                                          my $f = substr($t,0,1);
335                                          # repeatable subfileds. When we hit first one,  
336                                          # store CURRENT (up to that) in first repetition                                          push @subfields, ( $f, $sf_usage->{$f}++ || 0 );
337                                          # of this record. Then, new record with same  
338                                          # identifiers will be created.                                          # repeatable subfiled -- convert it to array
339                                          if ($val->{$f}) {                                          if ($val->{$f}) {
340                                                  push @{$rec->{$rec_nr}}, $val;                                                  if ( ref($val->{$f}) ne 'ARRAY' ) {
341                                                  $val = {                                                          $val->{$f} = [ $val->{$f}, $val ];
342                                                          i1 => $val->{i1},                                                  } else {
343                                                          i2 => $val->{i2},                                                          push @{$val->{$f}}, $val;
344                                                  };                                                  }
345                                          }                                          }
346                                          $val->{substr($t,0,1)} = substr($t,1);                                          $val->{substr($t,0,1)} = substr($t,1);
347                                  }                                  }
348                                    $val->{subfields} = [ @subfields ] if $args->{include_subfields};
349                          } else {                          } else {
350                                  $val = $l;                                  $val = $l;
351                          }                          }

Legend:
Removed from v.18  
changed lines
  Added in v.26

  ViewVC Help
Powered by ViewVC 1.1.26