You can simplify your code considerably by using the DBI "fetchrow_hashref" function (which gets each row as a reference containing the column names as keys and the column values as values) instead of storing the column data to separate parallel arrays. Something like this:
my $sth = $dbh->prepare( "SELECT pmid, abstract FROM PM_text " . "WHERE title LIKE '%E.coli%'" ); $sth->execute; my @text_refs = ($sth->fetchrow_hashref()); $sth->finish; ... for my $text_ref (@text_refs) { for my $cont_name (@cont_names) { if ($text_ref->{abstract} =~ m/$cont_name/im) { for my $bact_name (@bact_names) { if ($text_ref->{abstract} =~ m/$bact_name/im) { print "matched at text $text_ref->{pmid}, " . "for $cont_name and $bact_name\n"; $sth2->execute( $bact_name, $cont_name, $text_ref->{pmid} ); $sth3->execute( $cont_name, $text_ref->{pmid} ); } } } } }
Possibly you have a logic error here - the "$sth3->execute()" call depends only on the outer two loops, but it is occurring in the innermost loop. Thus if more than one bacteria name matches for a given abstract/contaminant pair, you will end up trying to insert duplicate records into that "PM_cont" table. Possibly the "$sth3->execute()" call should be moved out one level.

In reply to Re: Some problem pattern matching by amedico
in thread Some problem pattern matching by eMBR_chi

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.