first cut at parsing crolist csv files
authorDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 11 Sep 2013 15:39:19 +0000 (17:39 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 11 Sep 2013 15:39:19 +0000 (17:39 +0200)
crolist2marc.pl [new file with mode: 0755]

diff --git a/crolist2marc.pl b/crolist2marc.pl
new file mode 100755 (executable)
index 0000000..a233047
--- /dev/null
@@ -0,0 +1,37 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use autodie;
+
+use MARC::Record;
+use Data::Dump qw(dump);
+
+my $data;
+
+my $lines = 0;
+
+open(my $fh, '<', 'TEKTAG.csv');
+my $h = <$fh>; # header
+while(<$fh>) {
+       chomp;
+       my ( $idsl, $tag, $tagno, $id, $sfi, $sfino, $textkey, $textres ) = split(/,/,$_);
+
+       $tagno ||= 0;
+       $sfino ||= 0;
+
+       $id .= " " if length $id < 2;
+       $id .= " " if length $id < 2;
+       my ($i1, $i2) = split(//, $id, 2);
+
+       $sfi =~ s/^\$// || die "can't fix subfield [$sfi]";
+
+       $data->{$idsl}->{$tag}->[ $tagno ]->[ 0 ] = $i1;
+       $data->{$idsl}->{$tag}->[ $tagno ]->[ 1 ] = $i2;
+       $data->{$idsl}->{$tag}->[ $tagno ]->[ ( $sfino * 2 ) + 2 ] = $sfi;
+       $data->{$idsl}->{$tag}->[ $tagno ]->[ ( $sfino * 2 ) + 3 ] = $textkey . $textres;
+
+#      last if $lines++ > 5000;
+}
+
+warn dump($data);
+