<html> <body>

Thanks for the guys. I'm getting few errors. Here's the new code:

#!/usr/bin/perl -w use strict; use DBI; use File::Find; use Fcntl; use Getopt::Long; use Text::English; use constant TYPE_DEFAULT =>'article'; my (%opts, @files, $stop_words, $type); #User input GetOptions( \%opts, "dir=s", "stop=s", "ignore", "type=s", "numbers", "stem"); die usage() unless $opts{dir} && -d $opts{dir}; $opts{'type'} ||= TYPE_DEFAULT; #Get file names and build an array of files. find(sub{push @files, $File::Find::name}, $opts{dir}); $stop_words = load_stopwords($opts{stop}) if $opts{stop}; process_files(\@files, \%opts, $stop_words); sub load_stopwords { my $file = shift; my $words = {}; local *INFO, $_ or die "Can't open stop file: $file\n" unless -e $file; open INFO, $file or die "$!\n"; while(<INFO>) { next if /^#/; $words->{lc $1} = 1 if /(\S+)/; } close INFO; return $words; } sub process_files { #input variables: my($files, $opts, $stop_words) = @_; local( *FILE, $_ ); local $/ = "\n\n"; my $type = $opts{type}; my $dir = $opts{dir}; my %index; #Establish database variables: my($dbh, $sth1, $sth2); local(*FILE); local $/ = "\n\n"; my $file_id = 0; # initializing counter variable #Establish Database Connection $dbh = DBI->connect( "DBI:mysql:host=localhost;database=member +s", "gorillatrades", "kennyber", {PrintError=>0,RaiseE +rror=>1}); for ( my $file_id = 0; $file_id < @$files; $file_id++ ) { my $file = $files[$file_id]; my %seen_in_file; next unless -T $file; #print STDERR "Indexing $file\n"; #$index->{"!FILE_NAME:$file_id"} = $file; #Step 1: Create Library of Files: $sth1 = $dbh-> prepare("insert into library va +lues ($file, $dir, $type)"); $sth1-> execute(); open FILE, $file or die "Cannot open file: $file!\n"; while ( <FILE> ) { tr/A-Z/a-z/ if $opts{ignore}; s/<.+?>//gs; # Note this doesn't handle < or > in +comments or js while ( /([a-z\d]{2,})\b/gi ) { my $word = $1; next if $stop_words->{lc $word}; next if $word =~ /^\d+$/ && not $opts{number}; ( $word ) = Text::English::stem( $word ) if $o +pts{stem}; if ( ! $seen_in_file{$word} ) { $index{$word} .= ":" if ( exists( $in +dex{$word} )); $index{$word} .= $file_id; $seen_in_file{$word}++; } } #New Flava: Take Contents out of hash Table and into D +B foreach my $words (keys(%index)) { $sth2 = $dbh-> prepare('insert into catalog values ($words, $index{$words})'); $sth2 -> execute(); } } } } sub usage { my $usage = <<End_of_Usage; Usage: $0 -dir directory [options] The options are: -dir directory where files exist -ignore Case-insensitive index -stop Path to stopwords file -type Type of file, either email or article -numbers Include numbers in index -stem Stem words End_of_Usage return $usage; }

Now, I'm getting these errors:

perl libbuilder.pl -dir www/members/ -type= email Option type requires an argument DBD::mysql::st execute failed: You have an error in your SQL syntax ne +ar ' article)' at line 2 at libbuilder.pl line 91. Issuing rollback() for database handle being DESTROY'd without explici +t disconnect().
I know the second error requires a proper call to destroy the db hanlder. What gives /w the constant error?

In reply to Re: Finding local vs Global Error by Cappadonna3030
in thread Finding local vs Global Error 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.