Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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"; }

Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://700458]
[Lady_Aleena]: SOB! Now I'm really trying to get qx(mp3info -p "%S" $file) but the spaces in the filenames are kicking my butt.

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2017-04-23 23:42 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (433 votes). Check out past polls.