?
Solved

search code

Posted on 2000-01-21
3
Medium Priority
?
194 Views
Last Modified: 2010-03-05
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";
}
}
}

                                 
0
Comment
Question by:boofulls
  • 2
3 Comments
 
LVL 3

Expert Comment

by:guadalupe
ID: 2374574
See the original there was an error in the regex.
0
 

Author Comment

by:boofulls
ID: 2374853
sorry?
can u repost working code?
thanks
0
 
LVL 3

Accepted Solution

by:
guadalupe earned 400 total points
ID: 2374870
#!/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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question