Gossamer Forum
Home : General : Perl Programming :

Search Code

Quote Reply
Search Code
I have the following code:

Quote:
@results = grep(/$searchstr/,@mydata);
if ($#results >= 0) {
$count=0;
$numb=1;
$period=".";
foreach $i (@results) {
chomp($i);
($link,$name,$descrip,$keywords,$game) = split(/\|/,$i);

Its working all right. My question is: If I have a database of 3,000 lines it will be fast? Or there is a better code? Its just a simple search, not a sofisticated one like Links Manager.

Thiago Moretti
Quote Reply
Re: Search Code In reply to
Well, it could definately use some work. Right away you would get huge performance benefits by changing:

grep (/$searchstr/, @mydata)

to:

grep (/$searchstr/o, @mydata)

as then you won't need to rebuild the regular expression 3,000 times. You would also be better off going through the file line by line rather then sucking it all into one array.

Hope that helps,

Alex