bobbyboy has asked for the wisdom of the Perl Monks concerning the following question:
I have managed to get this search engine to work on my site but when you type in a keyword which does not appear within the site you just get a blank screen response. I want to give a response of Sorry was unable to match you response or something along those lines. It would be great if someone could help me solve this problem. Here is the code below.
Thanks
bobbyboy
#!/usr/bin/perl5 require "get_form_data.pl"; &get_form_data(); $search_term = $FORM{'search'}; print "Content-type: text/html\n\n"; opendir(DIR, "."); while($file = readdir(DIR)) { next if($file !~ /.html/); open(FILE, $file); $found_match = 0; $title = ""; while(<FILE>) { if(/$search_term/i) { $found_match = 1; } if((/<TITLE>/) || ($found_title)) { if((/<\/TITLE>/) && (/<TITLE>/)) { chop; $title = $_; $title =~ s/<TITLE>//g; $title =~ s/<\/TITLE>//g; } else { if($found_title == 1) { $title = $_; $found_title = 2 } elsif($found_title == 2) { $found_title = 0; } else { $found_title = 1; } } } } if($found_match) { print "<A HREF=\"$file\">$title</A>\n"; print "<BR>\n"; } close(FILE); } closedir(DIR); exit;
Edited 2001-04-03 by mirod: added <code> tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sorry message
by c-era (Curate) on Apr 03, 2001 at 16:08 UTC | |
|
Re: Sorry message
by cLive ;-) (Prior) on Apr 03, 2001 at 18:14 UTC | |
|
Re: Sorry message
by sutch (Curate) on Apr 03, 2001 at 16:10 UTC |