3 # this utility will convert some (or all, defined by regex)
4 # fields into marc file from one or more CDS/ISIS files
6 # 2004-02-23 Dobrica Pavlinusic <dpavlin@rot13.org>
8 # if ISIS databases are named same as directories in which they
9 # reside, you can specify just directories (so that shell globing work)
12 # ./isis2marc.pl all.marc /mnt2/*/LIBRI
19 # to select all fields use something like /./
20 my $field_filter = '^700$';
22 my $marc_file = shift @ARGV || die "Usage: $0 [MARC file] [ISIS db]...";
26 # it seems that I can't specify invalid template for 005 and prevent
27 # output from creating field 005
28 #$num->add_005s({record=>1});
35 foreach my $db_file (@ARGV) {
37 print "reading '$db_file'";
40 $db_file =~ s,([^/]+)/*$,$1/$1,;
43 my $db = OpenIsis::open( $db_file );
44 my $maxmfn = OpenIsis::maxRowid( $db ) || 1;
46 print " [rows: $maxmfn]\n";
48 my $progress_len = 50;
50 my $step = int($maxmfn/$progress_len);
51 $step = 1 if ($step == 0);
55 for (my $mfn = 1; $mfn <= $maxmfn; $mfn++) {
56 print "." if ($mfn % $step == 0);
57 my $row = OpenIsis::read( $db, $mfn );
58 foreach my $fld (keys %{$row}) {
59 next if ($fld !~ m/$field_filter/);
64 foreach my $sf (@{$row->{$fld}}) {
68 next if ($stored{$sf} > 1);
71 while ($sf =~ s/\^(\w)([^\^]+)//) {
74 # delete last subfield delimiter
75 $sf = "" if ($sf =~ /\^\w*$/);
79 } elsif ($sf && $sf !~ /^(\^\w)*\s*$/) {
80 # regex above remove empty subfields
87 $num=$marc->createrecord();
90 $marc->addfield({record=>$num,
100 printf "\t%d (%0.2f%%) t: %d\n",$new,($new*100/$maxmfn),$total;
103 $marc->output({file=>"> $marc_file",'format'=>"usmarc"})