my $inputfile = "file.txt";
my $dbh = DBI->connect("dbi:Pg:dbname=db;host=dbhost",
"user", "passwd", {AutoCommit => 1});
unless (open(INPUT, "$inputfile"))
{
print "ERROR: Can't open file for reading : $!\n";
}
while()
{
# splitting on tab character
my @data = split("\t", $_);
# assigning varables
my $did1 = $data[0];
my $did2 = $data[1];
my $score1 = $data[2];
my $score2 = $data[3];
if(($score1 >=70) && ($score2 >=60))
{
my $sth1 = $dbh->prepare("select d_id, c_id from d where d_id = '$did1';");
$sth1->execute();
my $sth2 = $dbh->prepare("select d_id, c_id from d where d_id = '$did2';");
$sth2->execute();
my $array_ref1 = $sth1->fetchall_arrayref();
my $array_ref2 = $sth2->fetchall_arrayref();
foreach my $row1(@$array_ref1)
{
my ($did1, $cid1) = @$row1;
foreach my $row2(@$array_ref2)
{
my ($did2, $cid2) = @$row2;
if($cid2 != $cid1)
{
print "$did1, $did2, $cid1, $cid2\n";
}
}
}
}
}
close(INPUT);
}
####
A34253 S43154 70 67
C31243 C31243 70 73
Y54231 W65313 70 71
U65242 B65231 70 70
Z23154 Z23154 70 65