#!/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);

