cleanup ids correctly (only \w and \d allowed)
authorDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 22 Nov 2023 13:50:24 +0000 (14:50 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 22 Nov 2023 13:50:24 +0000 (14:50 +0100)
upari.pl

index 428a2fa..7c2cc81 100755 (executable)
--- a/upari.pl
+++ b/upari.pl
@@ -95,8 +95,7 @@ foreach my $val ( 1 .. 4 ) {
                $stat->{file}->{$file}->{lines}++;
                $stat->{file}->{$file}->{columns}->{ $#$row }++;
 
-               if ( ! exists $stat->{file}->{$file}->{header} ) {
-                       $stat->{file}->{$file}->{header} = $row;
+               if ( ! exists $data_headers[$val] ) {
                        $data_headers[$val] = $row;
                        next;
                }
@@ -104,7 +103,7 @@ foreach my $val ( 1 .. 4 ) {
                my $c_id = $row->[0];
                my $c_s = $row->[1];
                my $c_r = $row->[2];
-               $row->[0] =~ s/[^A-Z0-9]+//g && $stat->{file}->{$file}->{corrupt_id}->{$c_id}++ && print 'c0';
+               $row->[0] =~ s/[^\w\d]+//ig && $stat->{file}->{$file}->{corrupt_id}->{$c_id}++ && print 'c0';
                $row->[1] =~ s/\D+//g && $stat->{file}->{$file}->{corrupt_s}->{$c_s}++ && print 'c1';
                $row->[2] =~ s/\D+//g && $stat->{file}->{$file}->{corrupt_r}->{$c_r}++ && print 'c2';
                my $id = join('-',
@@ -188,11 +187,11 @@ foreach my $id ( sort keys %{ $stat->{_} } ) {
                                }
 
                                my $o = delete $stat->{_}->{$id};
-                               die "FATAL: 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;
@@ -253,6 +252,7 @@ store $keys, $keys_file;
 
 my $merge_file = 'merge.storable';
 store $merge_ids, $merge_file;
+#print "XXX merge_ids = ", dump($merge_ids);
 
 my $out_file = 'merged.csv';
 print "out_file $out_file";