search code

i got this code but it doesnt seem to work
i have a html interface that sends a word and a directory to this perl script
the script _should_ return a list of all files in that dir that contain the word......



#!/usr/local/bin/perl

use lib "/usr/local/depot/perl5.005_02/lib/5.00502";
use CGI;
use CGI::Carp 'fatalsToBrowser';
use File::Find;

$myCGI = new CGI;
$dir = $myCGI->param('dir');
$word = $myCGI->param('text1');

print $myCGI->header, $myCGI->start_html;
 print "<center><BODY BGCOLOR=#CCCCCC link=\"black\" alink=\"black\" vlink=\"bla
ck\">";

# This will call sub rename_it for each file found, and will recurse
find(\&find_word, "$dir");
                     
sub find_word
{
# $File::Find::name now has the full path and name of the file
open(FILE, "$File::Find::name")

while ($line = <FILE>)
{
#match word use i for case INSENITIVE
if ($line =~ /$word/i)
{
#Make bold and add link
$line =~ s/($word)/<a href="show_text.cgi?$File::Find::name"><b>$1</b></a>/g;

#Output line to browser
print "\n$line\n";
}
}
}

                                 
boofullsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

guadalupeCommented:
See the original there was an error in the regex.
0
boofullsAuthor Commented:
sorry?
can u repost working code?
thanks
0
guadalupeCommented:
#!/usr/local/bin/perl

#use lib "/usr/local/depot/perl5.005_02/lib/5.00502";
#use CGI;
#use CGI::Carp 'fatalsToBrowser';
use File::Find;

#$myCGI = new CGI;
#$dir = $myCGI->param('dir');
#$word = $myCGI->param('text1');

#print $myCGI->header, $myCGI->start_html;
#print "<center><BODY BGCOLOR=#CCCCCC link=\"black\" alink=\"black\" vlink=\"black\">";

$word = "Set-Cookie";

$dir = "./";


# This will call sub rename_it for each file found, and will recurse
find(\&find_word, "$dir");
                     
sub find_word
{
# $File::Find::name now has the full path and name of the file
open(FILE, "$File::Find::name");

      while ($line = <FILE>)
      {
      #match word use i for case INSENITIVE
                  if ($line =~ /$word/)
                  {
                  #Make bold and add link
                  $line =~ s!($word)!<a href="show_text\.cgi\?$File::Find::name"><b>$1</b></a>!g;

                  #Output line to browser
                  print "\n$line\n";
                  }
      }
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.