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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help in debugging

Status
Not open for further replies.

johnsbn

Technical User
Mar 23, 2010
12
0
0
US
I have two files with five columns each. I want to compare those two files and if the 1st and 3rd columns match, then I'd want to compute the difference between 5th column values. Here's what I have and it doesn't seem to work (no outputs). Can somebody help please?



#! /usr/bin/perl

$dir1="."; $file1="$dir1/file1.rpt";
%at1_map;

open( SYN, "$file1") or die "Cant open $syn";
$bracket=0;
while ( <SYN> )
{
$line = $_;
($start,$start_cell,$end,$end_cell,$at,@words) = split (/\s+/, $line);

if ($line =~ /^\s*Startpoint/) { $bracket=0; }
elsif ($line =~ /^\s*---/) { $bracket=1; }
elsif ( $bracket == 1 && @words > 2)
{
$at1_map{$start.$end}=$at;
}
}
close (SYN);

$dir2="."; $file2="$dir2/cc.rpt";
%at2_map;

open( SYN, "$file2") or die "Cant open $syn";
$bracket=0;
while ( <SYN> )
{
$line = $_;
($start,$start_cell,$end,$end_cell,$at,@words) = split (/\s+/, $line);

if ($line =~ /^\s*Startpoint/) { $bracket=0; }
elsif ($line =~ /^\s*---/) { $bracket=1; }
elsif ( $bracket == 1 && @words > 2)
{
$at2_map{$start.$end}=$at;
}
}
close (SYN);


open (OUTFILE, ">diff.out") or die "Cannot open $outfile for writing \n";

@diff_arr;
foreach $key ( keys %at1_map )
{
if ( $at1_map{$key} != 0 && $at2_map{$key} != 0 ) { $diff=$at1_map{$key}-$at2_map{$key}; push (@diff_arr,$diff); }
}
print OUTFILE @diff_arr;

close OUTFILE;
 
>> What separates the columns, commas?
one or more spaces. These are pretty huge files, 3G each. Any alternative suggestions are welcome.
 
It would help if you supplied a few example lines of the input data and the expected output for that data.

Also, please post code between [ignore]
Code:
 ...
[/ignore] tags.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top