7 # apt install libtext-csv-perl
9 use Data::Dump qw(dump);
11 my @files = qw( 1.csv 2.csv 3.csv 4.csv );
16 foreach my $nr ( 1 .. 4 ) {
20 my $csv = Text::CSV->new ({ binary => 1, auto_diag => 1 });
21 open my $fh, "<:encoding(utf8)", $file or die "$file: $!";
22 while (my $row = $csv->getline ($fh)) {
23 $stat->{lines}->{$nr}++;
24 $stat->{ $file }->{lines}++;
31 my $num = $row->[0]; $num =~ s/\D//g;
33 $stat->{num}->{len}->{ length($num) }++;
35 my $key_id = $row->[1] . '-' . $row->[2] . 's' . int( $row->[4] );
38 push @{ $keys->{ $key_id }->{ $num } }, uc $row->[0];
40 if ( $num && $nr > 1 && ! exists $stat->{_}->{ $id } ) {
41 $stat->{error}->{new_exact}->{$nr}++;
42 if ( exists $keys->{ $key_id }->{ $num } ) {
43 my @found = @{ $keys->{ $key_id }->{ $num } };
46 print "MAPPED $nr $row->[0] to $id\n";
47 $stat->{mapped}->{$nr}++;
48 } elsif ( $#found > 0 ) {
49 print "ALIAS $nr $num into ",dump( @found ),$/;
50 $stat->{alias}->{$nr}++;
53 $stat->{error}->{new_num}->{$nr}++;
54 #print "ERROR $id new in $file\n";
58 $stat->{exists}->{$nr}++ if exists $stat->{_}->{ $id };
60 push @{ $stat->{_}->{ $id } }, $nr;
66 print "# total = ",scalar keys %{ $stat->{_} }, $/;
67 foreach my $id ( keys %{ $stat->{_} } ) {
68 $stat->{count}->{ scalar @{ $stat->{_}->{$id} } }++;
69 $stat->{count_total}++;
71 print "# stat = ",dump( $stat );
72 #print "# keys = ",dump( $keys );