56a54f24bcb49b0992c71c64da5aa157d1680e96
[crolist2marc] / crolist2marc.pl
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use autodie;
5
6 use MARC::Record;
7 use Data::Dump qw(dump);
8 use utf8;
9
10 my $data;
11
12 my $lines = 0;
13
14 open(my $fh, '<', 'TEKTAG.csv');
15 my $h = <$fh>; # header
16 while(<$fh>) {
17         chomp;
18         my ( $idsl, $tag, $tagno, $id, $sfi, $sfino, $textkey, $textres ) = split(/,/,$_);
19
20         $tagno ||= 0;
21         $sfino ||= 0;
22
23         $id .= " " if length $id < 2;
24         $id .= " " if length $id < 2;
25         my ($i1, $i2) = split(//, $id, 2);
26
27         $sfi =~ s/^\$// || die "can't fix subfield [$sfi]";
28
29         my $text = $textkey . $textres; # FIXME fix CAPITAL letters in $textkey
30         $text =~ tr/^~]}\|[{@`/ČčĆćĐ𩹮ž/; # CROASCII (YUS|HRN) B1.002:1982
31
32         $data->{$idsl}->{$tag}->[ $tagno ]->[ 0 ] = $i1;
33         $data->{$idsl}->{$tag}->[ $tagno ]->[ 1 ] = $i2;
34         $data->{$idsl}->{$tag}->[ $tagno ]->[ ( $sfino * 2 ) + 2 ] = $sfi;
35         $data->{$idsl}->{$tag}->[ $tagno ]->[ ( $sfino * 2 ) + 3 ] = $text;
36
37 #       last if $lines++ > 5000;
38 }
39
40 warn dump($data);
41