Angharad has asked for the wisdom of the Perl Monks concerning the following question:
The text file looks like thismy $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(<INPUT>) { # 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); }
It prints out the results of the SQL query only if score1 is at least 70, score2 is as least 60 and the 'cid1' for 'did1' is not the same as 'cid2' for 'did2' (the cid codes are retrieved from the SQL query).A34253 S43154 70 67 C31243 C31243 70 73 Y54231 W65313 70 71 U65242 B65231 70 70 Z23154 Z23154 70 65
2006-06-01 Retitled by planetscape, as per Monastery guidelines
Original title: 'Feedback Appreciated'
|
---|