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;
#! /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;