Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Delimited files Comparision

by TedPride (Priest)
on Jul 28, 2008 at 04:43 UTC ( #700458=note: print w/ replies, xml ) Need Help??


in reply to Delimited files Comparision

Not exactly sure what the numbers 1, 2, 4, 8 represent, but here's a 5 or 10 minute hack job:

use strict; my ($handle, @header, @file1, @file2, $row, $col, @output); ### Load header data open ($handle, 'header.txt') || die "Can't load header file.\n"; while (<$handle>) { @_ = split /,/, $_; $_ = pop @_; chomp; push @header, $_; } close ($handle); ### Load file 1 as array of arrays open ($handle, 'file1.txt') || die "Can't load data file 1.\n"; while (<$handle>) { push @file1, [split /,/, $_]; } close ($handle); ### Load file 2 open ($handle, 'file2.txt') || die "Can't load data file 2.\n"; while (<$handle>) { push @file2, [split /,/, $_]; } close ($handle); ### Output header line print join "\t", @header; print "\n"; ### For each line, output x for fields with a difference for ($row = 0; $row <= $#file1; $row++) { @output = (); for ($col = 0; $col <= $#header; $col++) { push @output, $file1[$row][$col] ne $file2[$row][$col] ? 'x' : ''; } print join "\t", @output; print "\n"; }


Comment on Re: Delimited files Comparision
Download Code
Re^2: Delimited files Comparision
by harishnuti (Beadle) on Jul 28, 2008 at 06:56 UTC

    Well , thats Amazing, i would like to thanq for effort and spending some time in looking into my problem..
    sorry to say , the solution works absolutely fine for the above data, but rather i have 2 more points as below.

    * The file's shown is only an extract of large file, actual file has got 1 million records of which A9000 is one entry.
    * The file1 and file2 and header contains different tables data, i have Appended one more set of data ..
    How do i extend the same solution, Can we use Hash to store and then loop on differences?

    i have one more requirement, the date field i should skip based on some position in another file, i can handle this one..
    can i have some idea on the updated set of data, i will try my best to extend your solution.

      Thanks iam able to resolve the issue using methods of hash

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2014-10-25 22:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (149 votes), past polls