Hi
I give that as a starting point. Nr. 1 should be solved. the rest is an execise for tsk1979.
#!/usr/bin/perl
use warnings;
use strict;
use Text::CSV;
use Data::Dumper;
die "ERROR: You have to provide at least one csv file."
unless(@ARGV);
my %RESULT;
foreach my $filename (@ARGV) {
if(grep { $_ eq $filename } keys %RESULT) {
warn "WARN: Why dou you want to compare a file '$filename' whi
+ch you have read already. Skipped.";
next;
}
my $csv = Text::CSV->new(
{ binary => 1 }
) or die "Cannot use CSV: " . Text::CSV->error_diag ();
open my $fh, "<", $filename or die "ERROR: Can't open '$filename':
+ $!";
my $counter = 0;
while (my $row = $csv->getline($fh)) {
$counter++;
next if($counter < 2);
unless(@$row <= 11) {
die "ERROR: Line '$counter' of file '$filename' has wrong
+format. Check your data crap.";
}
my $index = $row->[0];
my $index_id = $row->[1];
$RESULT{$filename}->{$index}->{$index_id} = { 'record' => $row
+ };
}
$csv->eof or die "ERROR: Couldn't read csv file '$filename': " . $
+csv->error_diag();
close $fh;
}
# Missing keys
my %FOUND_KEYS;
my $files_loaded = scalar keys %RESULT;
foreach my $filename (keys %RESULT) {
foreach my $index (keys %{$RESULT{$filename}}) {
foreach my $index_id (keys %{$RESULT{$filename}->{$index}}) {
my $key = $index . '@' . $index_id;
my $hash_ref = $FOUND_KEYS{$key} || {};
$hash_ref->{$filename} = 1;
$FOUND_KEYS{$key} = $hash_ref;
}
}
}
foreach my $key (keys %FOUND_KEYS) {
if(scalar keys %{$FOUND_KEYS{$key}} != $files_loaded) {
print "INFO: Key combination '$key' only found in the followin
+g files: " . join(', ', sort keys %{$FOUND_KEYS{$key}}) . "\n";
}
}
Best regards
McA