
perlkid
stranger
Feb 22, 2000, 6:56 PM
Post #4 of 13
(5743 views)
|
Hi Cure, Hi Brian, I'm very appreciative of the responses. I have been trying to get this to work all day but even with your code's I was unsuccessful. I was trying to make my original post short and simple so people would not be confused but I think it would be better if I said exactly my problem and what I'm trying to do. Here it goes, I have a data base called afkey.db and I have a small code that reads the database and matches any word with the form's input. It is a simple search engine. And when it finds a match in that database I want it to print location to search engine (A) with that key word as the query. I have been able to do that, but when I want to add an else statement so that when there is no match in the data base it will go to search engine (B) but it will go there all the time, regardless of the keywords in the file. With the else statement, the only time it will go to search engine (A) is when I type in what's in the first line. Other wise it always goes to search engine (B). I know that I’m typing in the right keywords, I mean; I open up the database and there right there. It's supposed to be like a redirect based on the keywords in a file (afkey.db). Well now that you know what I am trying to accomplish, here is the code. ______________________________________________________________________ %in = &parse_form; open(FILE,"</path/to/cgi-bin/database/afkey.db"); @data=<FILE>; close(FILE); foreach $line(@data) { @words=split(/\|/,$line); $words[0]=lc($words[0]); if ($words[0] eq "$in{'qry'}") { print "location:http://www.mysite.com/cgi-bin/redirect.pl?search=$words[0]&whereto=test&perpage=10\n\n"; } else { print "location:http://www.mysite.com/cgi-bin/redirect.pl?search=$in{'qry'}&whereto=search2&perpage=10\n\n"; } } sub parse_form { my (@pairs, %in); my ($buffer, $pair, $name, $value); if ($ENV{'REQUEST_METHOD'} eq 'GET') { @pairs = split(/&/, $ENV{'QUERY_STRING'}); } elsif ($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); } else { &cgierr('You cant run this script from telnet/shell.'); } PAIR: foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; ($value eq "---") and next PAIR; exists $in{$name} ? ($in{$name} .= "~~$value") : ($in{$name} = $value); } return %in; } ______________________________________________________________________ My main problem is that with that code, the only time it goes to the test engine (search engine A) is when I type in the keyword in the first line of the database. Thank you guys so much, perlkid [This message has been edited by perlkid (edited 02-22-2000).]
|