/[MARC-Fast]/trunk/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/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 23 by dpavlin, Sun Nov 4 22:44:42 2007 UTC
# Line 7  use Data::Dumper; Line 7  use Data::Dumper;
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 275  sub last_leader { Line 275  sub last_leader {
275    
276  Read record with specified MFN and convert it to hash  Read record with specified MFN and convert it to hash
277    
278    my $hash = $marc->to_hash($mfn);    my $hash = $marc->to_hash( $mfn, include_subfields => 1, );
279    
280  It has ability to convert characters (using C<hash_filter>) from MARC  It has ability to convert characters (using C<hash_filter>) from MARC
281  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 302  sub to_hash {
302    
303          my $mfn = shift || confess "need mfn!";          my $mfn = shift || confess "need mfn!";
304    
305            my $args = {@_};
306    
307          # init record to include MFN as field 000          # init record to include MFN as field 000
308          my $rec = { '000' => [ $mfn ] };          my $rec = { '000' => [ $mfn ] };
309    
# Line 321  sub to_hash { Line 323  sub to_hash {
323                          # has identifiers?                          # has identifiers?
324                          ($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/);
325    
326                            my $sf_usage;
327                            my @subfields;
328    
329                          # has subfields?                          # has subfields?
330                          if ($l =~ m/\x1F/) {                          if ($l =~ m/\x1F/) {
331                                  foreach my $t (split(/\x1F/,$l)) {                                  foreach my $t (split(/\x1F/,$l)) {
332                                          next if (! $t);                                          next if (! $t);
333                                          my $f = substr($t,0,1);                                          my $f = substr($t,0,1);
334                                          # repeatable subfileds. When we hit first one,  
335                                          # store CURRENT (up to that) in first repetition                                          push @subfields, ( $f, $sf_usage->{$f}++ || 0 );
336                                          # of this record. Then, new record with same  
337                                          # identifiers will be created.                                          # repeatable subfiled -- convert it to array
338                                          if ($val->{$f}) {                                          if ($val->{$f}) {
339                                                  push @{$rec->{$rec_nr}}, $val;                                                  if ( $sf_usage->{$f} == 2 ) {
340                                                  $val = {                                                          $val->{$f} = [ $val->{$f}, $val ];
341                                                          i1 => $val->{i1},                                                  } else {
342                                                          i2 => $val->{i2},                                                          push @{$val->{$f}}, $val;
343                                                  };                                                  }
344                                          }                                          }
345                                          $val->{substr($t,0,1)} = substr($t,1);                                          $val->{substr($t,0,1)} = substr($t,1);
346                                  }                                  }
347                                    $val->{subfields} = [ @subfields ] if $args->{include_subfields};
348                          } else {                          } else {
349                                  $val = $l;                                  $val = $l;
350                          }                          }

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

  ViewVC Help
Powered by ViewVC 1.1.26