From 02c793be8d3449a1fe96da251c820b1a9addcc22 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Wed, 22 Nov 2023 12:33:47 +0100 Subject: [PATCH] cleanup after merge, produce valid output --- upari.pl | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/upari.pl b/upari.pl index 0dbb777..428a2fa 100755 --- a/upari.pl +++ b/upari.pl @@ -188,15 +188,17 @@ foreach my $id ( sort keys %{ $stat->{_} } ) { } my $o = delete $stat->{_}->{$id}; - warn "can't find $id" if ! $o; + die "FATAL: can't find $id" if ! $o; + + my ( $id_s, $s, $r ) = split('-', $id); + my $key_s = "$s-$r"; + foreach my $val ( @$o ) { print '.'; push @{ $stat->{_}->{ $m_id } }, $val; print "++ $m_id $val "; $stat->{merge_val}->{$val}++; - my ( $id_s, $s, $r ) = split('-', $id); - my $key_s = "$s-$r"; die "ERROR merge: $val $id $m_id exists",dump( $merge_ids->{$val}->{$key_s}->{$id_s} ) if exists $merge_ids->{$val}->{$key_s}->{$id_s}; my $m_id_s = (split('-',$m_id,3))[0]; @@ -207,6 +209,10 @@ foreach my $id ( sort keys %{ $stat->{_} } ) { $data->{$key_s}->{$m_id_s}->{$val} = $o_row; } + my @not_empty = sort keys %{ $data->{$key_s}->{$id_s} }; + die "FATAL: $id_s not empty" if @not_empty; + delete $data->{$key_s}->{$id_s}; # FIXME check before cleanup + print "result val=",dump( $stat->{_}->{ $m_id } ), " result_elements=", scalar @{ $stat->{_}->{ $m_id } }, $/; } $stat->{merge}++; @@ -256,18 +262,17 @@ print $out_fh join(',', map { @{ $data_headers[$_] } } 1 .. 4 ), "\n"; foreach my $key ( sort keys %$data ) { print " $key"; foreach my $id ( sort keys %{ $data->{$key} } ) { - print $out_fh "## $id ## "; + #print $out_fh "## $id ## "; foreach my $val ( 1 .. 4 ) { if ( my $id_data = $data->{$key}->{$id}->{$val} ) { print $out_fh join(',', @$id_data); } else { - print $out_fh ( '_' x $#{ $data_headers[$val] } ) ; # FIXME +1? + print $out_fh ( ',' x $#{ $data_headers[$val] } ) ; # FIXME +1? } - print $out_fh '|' if $val < 4; + print $out_fh ',' if $val < 4; } print $out_fh "\n"; } - print $out_fh "\n"; } close $out_fh; print "\n", -s $out_file, " bytes created\n"; -- 2.20.1