I have a few suggestions.

unless (open(INPUT, "$inputfile")) { print "ERROR: Can't open file for reading : $!\n"; }

First, there's no need to quote $inputfile, just pass the scalar as the parameter to open. Second, although you check for an open error (good!) you don't do anything if it fails, aside from printing the error message. I would rewrite it using the following standard Perl idiom:

open INPUT, $inputfile or die "Can't open $inputfile for reading: $!";

Even better, you may want to use a more modern lexical filehandle instead of a global one, but this isn't a big deal for a small script, IMHO.

my @data = split("\t", $_); # assigning varables my $did1 = $data[0]; my $did2 = $data[1]; my $score1 = $data[2]; my $score2 = $data[3];

Here you put a bunch of stuff in @data just to take it out again. Instead, you can use a parallel assignment to make it more clear:

my ( $did1, $did2, $score1, $score2 ) = split "\t";

Note that I also ommitted the $_ from the split, since split works on $_ by default.

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();

This is the biggest red flag for me. You're not using placeholders! What happens if someone sneaks some nasty SQL into $did1? Or if $did2 contains some characters that need escaping? You should always use DBI placeholders (see the DBI documentation for a complete explanation.)

my $sth1 = $dbh->prepare("select d_id, c_id from d where d_id = ?"); $sth1->execute( $did1 ); my $sth2 = $dbh->prepare("select d_id, c_id from d where d_id = ?"); $sth2->execute( $did2 );

Finally, I'm assuming you've got strict and warnings turned on but you just forgot to paste that, right? :) You are using lexical variables well and the code seems simple and straightforward.


In reply to Re: Feedback Appreciated on text-parsing, SQL querying subroutine by friedo
in thread Feedback Appreciated on text-parsing, SQL querying subroutine by Angharad

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.