Hi All,
I am new to Perl and I have been grabbing code here and there to make a
search engine for a site. - Posted below.
What I have works but is incredibly slow and doesn't report back when a
match is not found.
I have been working with "CGI Programming with Perl" from O'Rielly but,
haven't had much luck with the creating custom modules for the more
professional search engine they suggest. I will attempt that and perhaps
post to this list again if I hit any snags.
Any helpful hints or URL's would be appreciated.
Thanks for being there.
Steve Vargas
PS The form for the code below is at:
http://www.musicfan.com/search.html
and the Perl Code is below.
#######Search Engine Code - Mere Beginnings######
#!/usr/bin/perl
require "get_form_data.pl";
&get_form_data();
$search_term = $FORM{'search'};
print "Content-type: text/html\n\n";
&search("..");
print <<EOF;
<HTML>
<HEAD>
<TITLE>
Search
</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
EOF
foreach $file (@found_set)
{
$_ = $file;
s/..\/html\///g;
$file = $_;
$newfile = $file;
if(/htm/) {
print "<A HREF=\"/$newfile\">$newfile</A>\n";
print "<BR>\n";
}
}
print <<EOF;
</BODY>
</HTML>
EOF
exit;
sub search
{
local ($dir) = @_;
if($dir eq ".")
{
opendir(DIR, ".");
$dir = "";
}
else
{
opendir(DIR, $dir);
$dir .= "/";
}
foreach $file (sort readdir(DIR))
{
next if($file eq "." || $file eq "..");
$file = $dir . $file;
next if(($file !~ /.htm/) && (!(-d $file)));
if(-d $file)
{
&search($file);
next;
}
open(FILE, $file);
$found_match = 0;
$title = "";
while(<FILE>)
{
if(/$search_term/i)
{
$found_match = 1;
}
if(/<TITLE>/)
{
chop;
$title = $_;
$title =~ s/<TITLE>//g;
$title =~ s/<\/TITLE>//g;
}
}
if($found_match)
{
push(@found_set, $file);
if($title eq "")
{
$title{$file} = $file;
}
else
{
$title{$file} = $title;
}
}
close(FILE);
print "<P>\n";
}
closedir(DIR);
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]