CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Search Engine in Perl?

 



ashwinv
stranger

Jul 23, 2001, 3:21 AM

Post #1 of 5 (1119 views)
Search Engine in Perl? Can't Post

Hi
I hope i can somehow sort this out. I just want to create a small search engine using Perl. 500 records at most. Is it possible??
I have tried to create one with a DBM database, but have been unable to do so. I have been able to make the script to add the info to the DB...but i am having trouble when searching the Database. Below is the script which i have got so far, but it doesn't work. I think the problem is mainly with the "foreach" statement.
-------------------------------------------------------------------------
The records are added as follows:
$site = $title.'&'.$url.'&'.$description.'&'.$keyword1.'&'.$keyword2.'&'.$keyword3;
--------------------------------------------------------------------------
#!/usr/bin/perl

use CGI;
$query = new CGI;
dbmopen(%engine,'engine',0666);

$name = $query->param('Keyword');
$i=0

$_ = $users{$name};
@data = split(/&/);

print "Content-type: text/html\n\n";

if ($keyword eq $data[3]||$data[4]||$data[5]) {
foreach $data[3] {
print "&title$i++=$data[0]";

} else {

print "&result=No results found";

}


dbmclose(%engine);
--------------------------------------------------------------------------

So whats wrong??
Hope you guys can help

Thanks in advance

Ash




Janie
stranger

Jul 23, 2001, 6:15 AM

Post #2 of 5 (1105 views)
Re: Search Engine in Perl? [In reply to] Can't Post

YOUR CODE...

Code
use CGI; 
$query = new CGI;
dbmopen(%engine,'engine',0666);

$name = $query->param('Keyword');
$i=0 # missing semicolon
$_ = $users{$name}; # why?
@data = split(/&/); # why not split() $users{$name} ?
#print "Content-type: text/html\n\n"; # print $query->header;

if($keyword eq $data[3]||$data[4]||$data[5]){ # can't do that
foreach $data[3]{ # nothing to foreach(). temp assignment - why?
print "&title$i++=$data[0]"; # can't interpolate these expressions
# missing right brace
}
else{
print "&result=No results found";
}

dbmclose(%engine);

So whats wrong??
Hope you guys can help
Thanks in advance
Ash

Hi Ash. Please don't be offended, but I think it would be good for you if you take the time to read through some good books or tutorials with explained sample code. Also, forget dbmopen() and use the more fashionable, flexible tie(), but do some reading first :) Here's some tie magic...


Code
use strict; 
use Fcntl;
use SDBM_File;
tie(my %hash, 'SDBM_File', 'hashdata', O_RDWR|O_CREAT, 0666)or die "Can't tie hashdata: $!";
%hash = ( A => "I'm here for the long haul", B => "So am I" ); # comment out after first assignment
print map{ $hash{$_}, br } keys %hash;
untie %hash;
my %hash = ( C => "I've got no staying power", D => "Neither have I" ); # comment out after first assignment
print map{ $hash{$_}, br } keys %hash;

Janie.
map{$,--%(5>>1)^0?push@y,$_:unshift@y,$_}sort(another=>Hacker=>Perl=>Just);for(1&1=>1|0){push@y,shift@y}print"@y"



ashwinv
stranger

Jul 23, 2001, 6:28 AM

Post #3 of 5 (1102 views)
Re: Search Engine in Perl? [In reply to] Can't Post

Hi
Not at all offended, we are all beginners at one time and i certainly am a beginner! Anyway, I was wondering where i could get some help on constructing a Perl based search engine. I don't mind how, but i would like to try and create one in about a week's time. If you could roughly tell me the easiest way to do this. (SQL, DBM, txt file). I have Learning Perl by O'reilly, so if you could tell me which chapters would help me to do this or weblinks i would be grateful. I don't mind learning from others scripts, as long as it is roughly explained to me (ie i don't just want to copy and paste).

Hope you can help

Thanks
Ash



(This post was edited by ashwinv on Jul 23, 2001, 5:29 AM)


mhx
Enthusiast / Moderator

Jul 23, 2001, 6:56 AM

Post #4 of 5 (1101 views)
Re: Search Engine in Perl? [In reply to] Can't Post

If you have access to the Perl Cookbook (O'Reilly), it has a chapter about database access with lots of examples. I can only recommend this book, it offers recipes for just about anything. However, some basic Perl knowledge is useful. You should also read the first couple of chapters from the Cookbook that deal with strings, arrays, hashes and pattern recognition, which are essential for a search engine. Although I have lots of books on Perl, I don't have 'Learning Perl', so I can't point you to any chapter in this book, but perhaps someone else can.
Hope this helps anyway.

-- Marcus


Code
s$$ab21b8d15c3d97bd6317286d$;$"=547269736;split'i',join$,,map{chr(($*+= 
($">>=1)&1?-hex:hex)+0140)}/./g;$"=chr$";s;.;\u$&;for@_[0,2];print"@_,"



Janie
stranger

Jul 23, 2001, 7:38 AM

Post #5 of 5 (1100 views)
Re: Search Engine in Perl? [In reply to] Can't Post

Hi Ash and Marcus. Get the whole kit'n'kaboodle by your heroes here:

http://hrg.dhtp.kiae.ru/corvin/perlbs/index.htm

They're free, but I don't think they're the latest editions.

Janie.

map{$,--%(5>>1)^0?push@y,$_:unshift@y,$_}sort(another=>Hacker=>Just=>Perl);for(1&1=>1|0){push@y,shift@y}print"@y"


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives