Forum Moderators: coopster & phranque

Message Too Old, No Replies

whats wrong with my search engine?

Please help!

         

adni18

2:23 am on Dec 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



#!/usr/bin/perl

use CGI::Carp qw(fatalsToBrowser);

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

@alreadydisplayed;

@todisplay;

@keywordlist=("good search engine","games bejeweled zuma bookworm");

@urllist=("http://www.google.com","http://www.example.com");

@descriptions=("A good search engine.","Great games.");

@titlelist=("Google","Popcap Games");

$qwords="Is thiS hellO";

@qsplitted=split(/\b/, $qwords);
$qlength=@qsplitted;

for($z=0;$z<@keywordlist;$z++)
{

$description=@descriptions[$z];

$keywords=@keywordlist[$z] . " " . $description;

$url=@urllist[$z];

$title=@titlelist[$z];

for($i=0;$i<$qlength;$i++)
{

$begin=@qsplitted[$i];
if($keywords =~ /\b$begin\b/g)
{

$a=0;
foreach $ranch (@alreadydisplayed)
{
if($ranch eq "$url\¦$keywords")
{
$a=1;
}
}

if($a == 0)
{
@alreadydisplayed=(@alreadydisplayed, "$url\¦$keywords");
@todisplay=(@alreadydisplayed, "$url\¦$description\¦$title");
}

}

}

}

for($begin=0;$begin<@todisplay;$begin++)

{

$currResult=@todisplay[$begin];

@spliced=split(/\¦/,$currResult);

$URL=@spliced[0];

$DESCRIPTION=@spliced;

$TITLE=@spliced[2];

print "\<b\>$TITLE</b> $DESCRIPTION $URL";

}

This code is a simple search engine I made, but for some reason, it won't display the first result correctly. Please help!

[1][edited by: jatar_k at 4:48 am (utc) on Dec. 3, 2004]
[edit reason] generalized url [/edit]

adni18

2:28 am on Dec 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Actually, it doesnt even perform the basic search function! PLEASE HELP!

VectorJ

4:12 am on Dec 4, 2004 (gmt 0)

10+ Year Member



The primary problem seems to be that you are accessing array elements incorrectly. In Perl an element of an array of, for example @descriptions, is:

$descriptions[$z]

not

@descriptions[$z]