elbow has asked for the wisdom of the Perl Monks concerning the following question:
Unfortunately (but perhaps unsurprisingly) Index Server does not fully cover the search criteria I wish to use. The use of wildcard searches is required, in any format (*stuff, st*ff, and stuff*). I've written a 'brute force' search program that matches on regular expressions, but with over 6000 documents to search it takes a while.
My question is this: does anybody have any ideas on how to improve the speed? My code for the search is
# Take each word from the array of search words and apply the qr// ope +rator to prevent a recompile for each regex. # Output the words to a new array using map (faster than foreach). @search_array = map { qr/\b$_\b/i } @and_array; # For each file within the directory while ( defined( $File = readdir(DIR) ) ) { # Skip the directory and parent directory (read as . and ..) next if $File =~ /^\.\.?$/; # Open the file for regular expression match open ( FILE, "$File" ) || die "Cannot open file $File: $!"; # Read file into an array @file_contents = (); @file_contents = <FILE>; close FILE; $nomatch = "0"; # Loop to match each search word held in the array against each line i +n the file. WORD: for $word ( @search_array ) { @found = (); @found = grep /$word/i, @file_contents; if ( scalar @found == 0 ) { $nomatch = "1"; last WORD; } } if ( $nomatch == "0" ) { $x = $x + 1; print LIST "$x $File ".$TelonDir.$in{'scope'}."\\$File \n"; } # End of while defined $File closedir DIR; close LIST;
Please go easy on me - I've learn't Perl from scratch by myself over the last 8 months and I'm certainly not the most adept!
elbow
Edit by dws to clean up tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Speed up the search
by derby (Abbot) on May 07, 2002 at 13:10 UTC | |
by perrin (Chancellor) on May 07, 2002 at 13:25 UTC | |
by Anonymous Monk on Jan 13, 2004 at 15:42 UTC | |
|
Re: Speed up the search
by Stegalex (Chaplain) on May 07, 2002 at 13:10 UTC | |
|
Re: Speed up the search
by tachyon (Chancellor) on May 07, 2002 at 15:39 UTC | |
|
Re: Speed up the search
by BUU (Prior) on May 07, 2002 at 12:40 UTC | |
by elbow (Scribe) on May 07, 2002 at 12:47 UTC | |
by Grunk (Initiate) on May 07, 2002 at 17:53 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |