Hello Monks,
I have a very slow search engine made with a CGI script, and it has been suggested to use FastCGI. I am just wondering if where you put the while loop matters, and if there is a better way/other options.
I have looked at mod_perl, but can't put anything on the server, so it won't do. Not sure if Plack is a better option.
Also, would it matter using readdir or File::Find with speed? Would it be faster to use one file which includes all of the files being looped through??
Here is the important code (I think):
#!/usr/bin/perl -wT
#What is the T for in -wT?
use strict;
use CGI qw(:standard);
use FCGI;
use File::Find;
require '/Users/jon/Desktop/stanford-postagger-full-2011-04-20/verbTen
+seChanger.pl';
#my $search_key = param('query');
my $search_key = "move";
# --- Different forms of the Searchword --- #
my @temp_changeverbforms = map changeVerbForm( $search_key, 0, $_ ), 1
+..4;
my @verbforms;
push (@verbforms, $search_key); # Watch extra for loop
foreach my $temp_changeverbforms (@temp_changeverbforms)
{
push (@verbforms, $temp_changeverbforms) unless ($temp_changeverbf
+orms eq "");
}
#my $c_verb = param('verb_only'); my $c_enabling = param('enabling');
+my $c_subject = param('subject');
#my $c_object = param('object'); my $c_prep = param('prep'); my $c_adj
+ = param('adjective');
#my $c_modnoun = param('modnoun');
my $category_id;
# --- Variables for required info from parser --- #
my $chapternumber; my $sentencenumber; my $sentence;
my $grammar_relation; my $argument1; my $argument2;
my @all_matches; ## RESULTS OF SEARCH
#if ($c_verb eq 'on')
# {
# if ($c_enabling eq 'on')
# {$category_id = 'xcomp';}
# elsif ($c_subject eq 'on')
# {$category_id = 'subj';}
# elsif ($c_object eq 'on')
# {$category_id = 'obj';}
# elsif ($c_prep eq 'on')
# {$category_id = 'prep';}
$category_id = 'subj';
# --Files -- #
#To change, keep curly at beginning, comment File::Find ,) at end, unc
+omment open
## readdir ## ##or glob ## ##or File::Find ##
my $dir = '/Users/jon/Desktop/stanford-postagger-full-2011-04-20/';
opendir(my $dh, $dir) or die $!; # Use a lexical directory handle.
my @files =
grep { -f } #Just to check if file
map { "$dir/$_" } #Just to check if file
grep { /^parsed.*\.txt$/ } #if parsed text
readdir($dh);
################ FCGI attempt ####################
while (FCGI::accept >= 0 ) {
for my $file (@files)
{
open(my $parse_corpus, '<', "$file") or die $!;
my @entirechapter = <$parse_corpus>;
my $entirechapter = join ('', @entirechapter); ##Flatten file
+(make one big string)
#To get each sent. and info in one string:
my @sentblocks = split (/Parsing\s/, $entirechapter); ##Remove
+ "Parsing" which is on the line of the chptnumber
$chapternumber = $1 if ($sentblocks[1] =~ /file:\s(\S+)\.txt/)
+;
foreach my $sentblock (@sentblocks)
{
foreach my $verbform (@verbforms)
{
##blah blah regex's, conditions, subroutine
## output ##
print header();
print start_html();
##blah blah
#print statements
} #End of file loop Could be moved up for speed?
print "</ol><br>";
print end_html();
} ##END of FCGI while loop!
p.s. The while loop is after I get all the files I want to loop through.
Thanks a lot, and don't hesitate to let me know if this was asked badly, or unclear, or if I have to make it more concise.