From: Shawn Boyette Date: Wed, 24 Jun 2009 19:20:18 +0000 (+0000) Subject: improved multifile handling X-Git-Url: http://git.equinoxoli.org/?p=migration-tools.git;a=commitdiff_plain;h=a08f66cfeb74ddef098fa4c07846e0af5df4ba66 improved multifile handling --- diff --git a/extract_holdings b/extract_holdings index 0557416..0ef270a 100755 --- a/extract_holdings +++ b/extract_holdings @@ -36,12 +36,15 @@ sub extract_holdings { # open main holdings file open HOLDINGS, '>', ($c->{prefix} . "-HOLDINGS.pg"); # create multi files - my @multifiles = <*HOLDINGS-MULT*>; - unlink @multifiles; + my $multis = $m->get_multis; + my %MULTIFILE = (); + for my $t ( keys %{$multis} ) { + for my $s ( keys %{$t}) + { open my $fh, ">", ($c->{prefix} . "-HOLDINGS-MULT-$t$s.pg"); $MULTIFILE{"$t$s"} = $fh } + } my $i = 0; # record counter my $j = 0; # holdings counter - my $multis = $m->get_multis; while ( $m->{data}{recs}[$i] ) { print HOLDINGS "BEGIN;\n\negid\thseq\t" unless $j; @@ -63,10 +66,8 @@ sub extract_holdings { # handle holdings multis for my $sub ( sort keys %{$multis->{$tagid}} ) { - open MULT, ">>", ($c->{prefix} . "HOLDINGS-MULT" . "$tagid$sub.pg"); for my $value ( @{$rec->{tags}[$holdidx]{multi}{$sub}} ) - { print MULT join("\t", $rec->{egid}, $j, $value), "\n" } - close MULT; + { my $fh = $MULTIFILE{"$tagid$sub"}; print $fh join("\t", $rec->{egid}, $j, $value), "\n" } }