Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

join command in perl

Status
Not open for further replies.

bcheong

IS-IT--Management
Jan 9, 2001
8
JP
Hi all,

Basically, what I'm trying to do is compare two large CSV files and find out which fields have changed since the last update. Based on that, I want to produce comparison files based on which field was different.

I know of a way to do this using the 'join' command in HP-UX (please see for details), but I would like to do this in Perl.

Would appreciate any help!

Cheers,
Ben
 
Code:
cmp file1 file2
diff file1 file2

to execute this in Perl use backticks

for example:-

Code:
print `cmp file1 file2`;


Kind Regards
Duncan
 
Ben,

If you really want to do this in Perl because the output of the utilities isn't enough for your needs

in the case of field updates, and not lines inserted

Then
open both files
process line by line
in the event of a change, push it on to an array for printing later
Code:
open FH1, "file1.csv";
open FH2, "file2.csv";
@FH1array=<FH1>;
@FH2array=<FH2>;
$loop=0;
foreach(@FH1array) {
  if ($_ ne $FH2array[$loop]) {
    @lineFH1=split /,/, $FH1array[$loop]; #assumes no commas in fields, otherwise ask Dunc nice for a regex
    @lineFH2=split /,/, $FH2array[$loop];
    ...
    code here to check which fields have changed
    pretty much similar to above foreach w/ loop var
    ...
  }
  $loop++;
}

There's a start, but you might be better off passing the results from a utility to an array, and parsing the resultant output to tart that up

HTH
--Paul


It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
Hi all,

Thanks for replies!
Paul, your reply was good start on. Many thanks for that!

Cheers,
Ben
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top