pojuse strict; my %data=(); scan (0,'File1.txt'); scan (1,'File2.txt'); compare('log.txt'); # input sub scan { my ($ix, $infile) = @_; open IN, '<', $infile or die "Could not open $infile : $!"; my $count=0; while (<IN>){ chomp; my ($key,$line) = split "\t",$_,2; $data{$key}[$ix] = $line; ++$count; } close IN; print "$count lines read from $infile\n"; } # output sub compare { my $logfile = shift; open LOG,'>',$logfile or die "Could not open $logfile : $!"; my $count = 0; # compare lines of data using key for my $key (sort keys %data){ if ($data{$key}[0] ne $data{$key}[1]){ my @f1 = split "\t",$data{$key}[0]; my @f2 = split "\t",$data{$key}[1]; for my $c (1..@f1){ if ($f1[$c-1] ne $f2[$c-1]){ print LOG "Row $key Column $c File 1 Value- $f1[$c-1] File 2 + Value- $f2[$c-1]\n"; ++$count; } } } } close LOG; print "$count lines written to $logfile\n"; }
In reply to Re: Column by Column Comparison
by poj
in thread Column by Column Comparison
by documents9900
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |