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


In reply to Re: Diff CSV files - But ignore certain fields by McA
in thread Diff CSV files - But ignore certain fields by tsk1979

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.