Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Column by Column Comparison

by poj (Parson)
on Mar 31, 2013 at 13:40 UTC ( #1026355=note: print w/ replies, xml ) Need Help??

in reply to Column by Column Comparison

Using a hash approach
use 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"; }
Comment on Re: Column by Column Comparison
Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1026355]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2016-05-25 00:37 GMT
Find Nodes?
    Voting Booth?