boofulls
asked on
search dirs
im a total novice to perl
id like code to do this
i want a drop down menu and a text
box and when people pick one option
from the drop down menu and enter a word
they will be given results.
the options in the drop down menu are
"X" "Y" and "Z" and these correspond to different directories (X Y and Z)
if i enter Z and the word "and"
i will be given these results
-the name of the file that matches the search
-the exact line that matches the search with the searched for word in bold
-a link that can be clicked which lets the use read the whole file (id like the text to come up in my browser in the same format as it is in the text file)
thank you
id like code to do this
i want a drop down menu and a text
box and when people pick one option
from the drop down menu and enter a word
they will be given results.
the options in the drop down menu are
"X" "Y" and "Z" and these correspond to different directories (X Y and Z)
if i enter Z and the word "and"
i will be given these results
-the name of the file that matches the search
-the exact line that matches the search with the searched for word in bold
-a link that can be clicked which lets the use read the whole file (id like the text to come up in my browser in the same format as it is in the text file)
thank you
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok im really conused with your answer but thanks for helping
can u post a basic working version that i can work on and improve?
and tell me what to improve in comments?
thanks
can u post a basic working version that i can work on and improve?
and tell me what to improve in comments?
thanks
That really is kinda basic in relation to what you want. But tell me what part you need help with and I'll try and clarify...
ASKER
can u post a simple html interface to a perl script that searches....
i cant seem to work out how to put it all together
thanks
i cant seem to work out how to put it all together
thanks
Are you on Unix or NT? Its a small difference but lets do it right...
ASKER
unix
OK, the html doc which has the form and calls th cgi would be like this:
########################## #####
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<FORM METHOD="POST" ACTION="dir_search.cgi">
Choose Dir: <SELECT NAME="dir">
<!-- CAUTION THE DIRS I HAVE PLACED AS VALUES IN THE OPTIONS MUST BE CHANGED
TO REAL DIRS ON YOUR SERVER!!!! DIRS WHICH YOU HAVE ACCESS TO!!!!!!!!! -->
<option value="/usr/home/docs">Tex t Dir</option>
<option value="/usr/home/htdocs">H TML Dir</option>
</SELECT><br>
Search Word: <INPUT TYPE="text" NAME="word"><br>
<INPUT TYPE="submit">
</FORM>
</BODY>
</HTML>
########################## ########## #
Read comment in above file!!!!
Then tage the cgi script I submitted above and save it as dir_search.cgi and remember to set the permissions to 775 using "chmod 775 dir_serach.cgi" or the same comand mangaed by your FTP prog such as WS-FTP. This should do it...
##########################
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<FORM METHOD="POST" ACTION="dir_search.cgi">
Choose Dir: <SELECT NAME="dir">
<!-- CAUTION THE DIRS I HAVE PLACED AS VALUES IN THE OPTIONS MUST BE CHANGED
TO REAL DIRS ON YOUR SERVER!!!! DIRS WHICH YOU HAVE ACCESS TO!!!!!!!!! -->
<option value="/usr/home/docs">Tex
<option value="/usr/home/htdocs">H
</SELECT><br>
Search Word: <INPUT TYPE="text" NAME="word"><br>
<INPUT TYPE="submit">
</FORM>
</BODY>
</HTML>
##########################
Read comment in above file!!!!
Then tage the cgi script I submitted above and save it as dir_search.cgi and remember to set the permissions to 775 using "chmod 775 dir_serach.cgi" or the same comand mangaed by your FTP prog such as WS-FTP. This should do it...
Ah one more thing. The following code:
#!/usr/local/bin/perl
#Turn on auto flush to avoid browser time out waiting for long dir seraches
{
}
$| = 1;
use File::Find;
&parseInput;
Change to:
#!/usr/local/bin/perl
#Turn on auto flush to avoid browser time out waiting for long dir seraches
$| = 1;
use File::Find;
&parseInput;
Merely removing a pair of brackets which were useless.
#!/usr/local/bin/perl
#Turn on auto flush to avoid browser time out waiting for long dir seraches
{
}
$| = 1;
use File::Find;
&parseInput;
Change to:
#!/usr/local/bin/perl
#Turn on auto flush to avoid browser time out waiting for long dir seraches
$| = 1;
use File::Find;
&parseInput;
Merely removing a pair of brackets which were useless.
# This will call sub rename_it for each file found, and will recurse
find(\&find_word, "$fields{'dir'}");
Sorry don't know how I did that.
find(\&find_word, "$fields{'dir'}");
Sorry don't know how I did that.
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\?$Fil e::Find::n ame"><b>$1 </b></a>!g ;
#Output line to browser
print "\n$line\n";
}
}
}
{
# $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\?$Fil
#Output line to browser
print "\n$line\n";
}
}
}
ASKER
beside each match that is returned can u print the name of the file in which the match appears?
thanks
thanks
#Make bold and add link
$line =~ s!($word)!<a href="show_text\.cgi\?$Fil e::Find::n ame"><b>Fi le: $File::Find::name - $1</b></a>!g;
$line =~ s!($word)!<a href="show_text\.cgi\?$Fil
Thank you for the double points and fogive me the mistakes, I've been busy and trying to do too many things at once. Thanks for the patience.
ASKER
no problem, thanks for your help, i would have been lost without u....
ASKER
if they select part of word then when they enter "and" they will get entries like "sand" and if they select exact word they will just get that exact word