Here is the revised code:

#!/usr/bin/perl -w use strict; use Fcntl; use DBI; use File::Basename; use Text::English; #input Words print "Give a list of words:\t"; my $query = <STDIN>; my @words = split(/\s*(?:,|\s+)/, $query); #File Type: print "Give a file type (email, article):\t"; my $type = <STDIN>; my %paths = search(\@words, $type); for my $val (keys %paths) { my $ft = $paths{$val}; print "$ft : $val \n"; } sub search { my($words, $type) = @_; my($dbh, $sth1, $sth2, $rule_append, $word, $file_index); my %matches; #Database Connection: $dbh = DBI->connect( "DBI:mysql:host=localhost;database=testd +b", "testuser", "testpass", {PrintError=>0,RaiseError= +>1}); #Establish Rules for file type: CASE: { if($type eq "email") { $rule_append = "filetype = \"email\" "; last CASE; } if($type eq "article") { $rule_append = "filetype = \"article\" "; last CASE; } $rule_append = "filetype = \"article\" OR \"email\" " +; }#End of Rule foreach $word(@$words) { my $match; ( $word ) = Text::English::stem( $word ); my @poss; #round 1: Find all file pertaining to word. my $statement1 = "SELECT files FROM catalog WHERE word + LIKE \"%$word%\" "; $sth1 = $dbh -> prepare($statement1); $sth1 -> execute(); while(my @val = $sth1 -> fetchrow_array()) { $match = $val[0]; #Get List of files. #Parse Files and Check for matches within. @poss = split(/:/, $match); foreach $file_index(@poss) { $sth2 = $dbh ->prepare("select filenam +e, filetype from library where filename + like \"%$file_index%\" and ".$rule_ap +pend); $sth2 -> execute(); if(my @val2 = $sth2->fetchrow_array()) { $matches{$val2[0]} = $val2[1] +; } } # All Relevant Files found. }# Cycle through all possible matches. } #End of word search loop return(%matches); #$dbh -> disconnect; }#End of search Function

Now, it runs through the DB w/o a problem, but now it dies on the search itself.

Give a list of words: test,diamonds,perl Give a file type (email, article): article Issuing rollback() for database handle being DESTROY'd without explici +t disconnect() at search.pl line 26, <STDIN> line 2.

In reply to Re: Trying to Debug DB Search by Cappadonna3030
in thread Trying to Debug DB Search by Cappadonna3030

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.