/[webpac]/trunk/to_hash.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

Annotation of /trunk/to_hash.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 678 - (hide annotations)
Sun Feb 27 23:07:35 2005 UTC (19 years, 1 month ago) by dpavlin
File size: 824 byte(s)
Experimental support for dBase .dbf files. Usege like this in all2xml.conf:

[hda]
       dbf_file=/data/drustvene/hda/ISO.DBF
       type=dbf
       dbf_codepage=cp852
       dbf_mapping=<<_END_OF_MAP_
ID_BROJ                001
ISBN_BROJ      010
SKUPINA1       200
SKUPINA2       205
SKUPINA4       210
SKUPINA5       215
SKUPINA6       225
SKUPINA7       300
ANOTACIJA      330
PREDMET1       610
PREDMET2       610
PREDMET3       510
UDK            675
REDALICA       700
SIGNATURA      990
_END_OF_MAP_

dbf type will use <isis> tag in import_xml and dbf_codepage will
override codepage specified in import_xml file.

Small code refactoring.


1 dpavlin 678 # This is slight modification of to_hash as included in Biblio::Isis
2     #
3     # This is incredibly bad (duplicate code), but it would have to wait for
4     # WebPac v2 to be fixed by extracting all file imported in sane OO way.
5    
6    
7     sub to_hash {
8     my $mfn = shift || confess "need mfn!";
9     my $row = shift || confess "need data";
10    
11     # init record to include MFN as field 000
12     my $rec = { '000' => [ $mfn ] };
13    
14     foreach my $k (keys %{$row}) {
15     foreach my $l (@{$row->{$k}}) {
16    
17     my $val;
18    
19     # has identifiers?
20     #($val->{'i1'},$val->{'i2'}) = ($1,$2) if ($l =~ s/^([01 #])([01 #])\^/\^/);
21    
22     # has subfields?
23     if ($l =~ m/[\^\$]/) {
24     foreach my $t (split(/[\^\$]/,$l)) {
25     next if (! $t);
26     $val->{substr($t,0,1)} = substr($t,1);
27     }
28     } else {
29     $val = $l;
30     }
31    
32     push @{$rec->{$k}}, $val;
33     }
34     }
35    
36     return $rec;
37     }
38    
39     1;

  ViewVC Help
Powered by ViewVC 1.1.26