elton247 has asked for the wisdom of the Perl Monks concerning the following question:

I thought this would be an easy thing but I am having major toubles with it. I am basically trying to create a search engine that will search a specified directory, return all the files in it, and search each file for the matching text. This is for a CGI script by the way.
if ($com eq "Submit Search") { opendir (TEMP, 'po'); @files = readdir(TEMP); foreach $file (@files) { open(FILE,"po/$file") || die "can't open "; $filein = <FILE>; close (FILE); # $filein =~ s/,/ /g; if (-d $file) {} elsif ($search =~ /$filein/i) { print "<a href=\"index.cgi?file=$file\">$file</a> +<br><br>"; } else {print "<br>File not Found<br>"; } } }
i am having trouble with the elsif ($search =~  /$filein/i) { part. $filein is a CSV file that looks something like this:
D04101,4/10/01,4,30,01,James Bernard,PO Box 4623,Chicago,IL,60680-4623 +,773-379-9873,,,Self-Inking Stamp Red
So if i search for "james", it comes up as "file not found" even though "james" is clearly in the file. But The File will be found if all it has in it is the word "james". Am i totally missing something. I hope you all can understand what i am looking for. Thanks Elton

Replies are listed 'Best First'.
(ichimunki) Re: trying to create search engine
by ichimunki (Priest) on Apr 13, 2001 at 01:17 UTC
    From the snippet you've got, I'm guessing that you really want elsif ($filein =~ /$search/i). Where $search is "james".
      You are totally right. it works perfect now. This sheads a lot of light on my use of regular expressions. Thanks
Re: trying to create search engine
by geektron (Curate) on Apr 13, 2001 at 03:33 UTC