Hello, Wise Perl Monks, I have this problem with pattern matching in an application I am trying to build. The script retrieves data from a database, and pushes these into appropriate arrays. One of those arrays contain abstracts from pubmed and the other two are lists of keywords to search for in the abstracts. Where the script finds cooccurence of those keywords in the abstract, it should then write the information into some other database tables. My problem is that apart from returning error of 'use of uninitialised values in pattern matching' the pattern matching component of the script just does not work. Being inexperienced in Perl I am unable to figure out what could be wrong. I would really appreciate your help. Thank you very much
#!/usr/bin/perl use strict; use warnings; use DBI; use lib'/usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/DBD/mys +ql.pm'; #retrieve names of bacteria and contaminants and store in arrays my $bactfilename = "Bacteria_names3.txt"; my @bact_names = get_data($bactfilename); my $contaminantname = "Contaminant_names4use.txt"; my @cont_names = get_data($contaminantname); #database details: my $ds = "DBI:mysql:Pmeddata:localhost"; my $user = "root"; my $passwd = "******"; #connect to database, prepare and execute SQL my $dbh = DBI->connect($ds,$user,$passwd) || die "Cannot connect to da +tabase!!"; my $sth = $dbh->prepare("SELECT pmid, abstract FROM PM_text WHERE titl +e LIKE '%E.coli%'"); $sth->execute; #arrays to hold pmid, and abstract my @abst_listing; my @abst_PMID; while (my @abstracts = $sth->fetchrow_array()){ push(@abst_PMID,$abstracts[0]); push(@abst_listing,$abstracts[1]); } $sth->finish; my $sth2 = $dbh->prepare("INSERT INTO PM_bacteria (bactname, assoc_con +t, pm_id) VALUES (?,?,?)"); my $sth3 = $dbh->prepare("INSERT INTO PM_cont (cont_name, pmed_id) VAL +UES (?,?)"); #WORKS WELL UP TO THIS POINT:THE FOLLOWING BIT DOES NOT WORK #use nested 'for' loops for pattern matching my $a; my $b; my $c; for ($a=0; $a<= scalar(@abst_listing); $a++){ for ($c=0; $c<= scalar(@cont_names); $c++){ if($abst_listing[$a] =~ m/$cont_names[$c]/im){ for($b=0; $b<= scalar(@bact_names); $b++){ if($abst_listing[$a] =~ m/$bact_names[$b]/im){ #insert into database; $sth2->execute($bact_names[$b],$cont_names[$c],$ab +st_PMID[$a]); $sth3->execute($cont_names[$c],$abst_PMID[$a]); print "matched at abst no $a , for $cont_names[$c] + and $bact_names[$b]\n"; } } } } } $sth2->finish; $sth3->finish; $dbh->disconnect; sub get_data{ my ($filename) = @_; unless (open(DATAFILE, $filename)){ print "Could not open file $filename!!\n"; exit; } my (@filedata) = <DATAFILE>; close(DATAFILE); return @filedata; }

In reply to 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.