<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<META content="MSHTML 6.00.5730.11" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT size=2>Hi All,</FONT></DIV>
<DIV><FONT size=2>I have a quick question.</FONT></DIV>
<DIV><FONT size=2>I'm using "opendir" and trying to get my search.cgi script to 
search in my main www directory instead of my cgi-bin </FONT></DIV>
<DIV><FONT size=2>as the HTML pages found can't be accessed there.</FONT></DIV>
<DIV><FONT size=2>I did this as a tutorial from a book I have.</FONT></DIV>
<DIV><FONT size=2>Here are my Env Variables:</FONT></DIV>
<DIV><FONT size=2><A 
href="http://www.autotection.com/cgi-bin/env_var.pl">http://www.autotection.com/cgi-bin/env_var.pl</A></FONT></DIV>
<DIV><FONT size=2>any help very appreciated.</FONT></DIV>
<DIV><FONT size=2>Thanks Steve</FONT></DIV>
<DIV><FONT size=2>############search.cgi</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>#!/usr/bin/perl<BR>&amp;get_form_data();<BR>$search_term = 
$FORM{'search'};<BR>print "Content-type: 
text/html\n\n";<BR>&amp;search(".");</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=2>sub get_form_data<BR>&nbsp;{<BR>&nbsp; # get the 
data<BR>read(STDIN, $buffer, $ENV{ 'CONTENT_LENGTH' } );</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=2>@pairs = split(/&amp;/, $buffer);<BR>foreach $pair 
(@pairs)<BR>{<BR>&nbsp; ($firstname, $value) = split(/=/, $pair);</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=2>&nbsp;$value =~ tr/+/ /;<BR>&nbsp;$value =~ 
s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;<BR>&nbsp;$value =~ 
s/&lt;!--(.|\n)*--&gt;//g;<BR>&nbsp;$FORM{$firstname} = $value;<BR>&nbsp; 
}<BR>}</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=2>print 
&lt;&lt;EOF;<BR>&lt;HTML&gt;<BR>&lt;HEAD&gt;<BR>&lt;TITLE&gt;<BR>Search<BR>&lt;/TITLE&gt;<BR>&lt;/HEAD&gt;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=2>&lt;BODY BGCOLOR="#FFFFFF"&gt;<BR>&lt;P&gt;Results of your 
search: $search_term&lt;/P&gt;<BR>EOF<BR>foreach $file 
(@found_set)<BR>{<BR>&nbsp;&nbsp;&nbsp; print "&lt;A 
HREF=\"$file\"&gt;$Title{$file}&lt;/A&gt;\n";<BR>&nbsp;&nbsp;&nbsp; print 
"&lt;BR&gt;\n";<BR>}<BR>if ((@found_set) != "") {<BR>&nbsp; print 
"&lt;H3&gt;Above Are Matches for the Search Term: 
$search_term&lt;/H3&gt;\n";<BR>} else {<BR>&nbsp; print "&lt;H3&gt;Sorry, no 
files found under the search term: $search_term&lt;/H3&gt;\n";<BR>}</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=2>print 
&lt;&lt;EOF;<BR>&lt;/BODY&gt;<BR>&lt;/HTML&gt;<BR>EOF<BR>exit;<BR>sub 
search<BR>{<BR>&nbsp;local ($dir) = @_;<BR>&nbsp;if($dir eq 
".")<BR>&nbsp;{<BR>&nbsp;&nbsp;opendir(DIR, ".");<BR>&nbsp;&nbsp;$dir = 
"";<BR>&nbsp;}<BR>&nbsp;else<BR>&nbsp;{<BR>&nbsp;&nbsp;opendir(DIR, 
$dir);<BR>&nbsp;&nbsp;$dir .= "/";<BR>&nbsp;}<BR>&nbsp;foreach $file (sort 
readdir(DIR))<BR>&nbsp;{<BR>&nbsp;&nbsp;next if($file eq "." || $file eq 
"..");<BR>&nbsp;&nbsp;$file = $dir . $file;<BR>&nbsp;&nbsp;next if(($file !~ 
/.htm/) &amp;&amp; (!(-d $file)));</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=2>&nbsp;&nbsp;if(-d 
$file)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&amp;search($file);<BR>&nbsp;&nbsp;&nbsp;next;<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;open(FILE, 
$file);<BR>&nbsp;&nbsp;$found_match = 0;<BR>&nbsp;&nbsp;$title = 
"";<BR>&nbsp;&nbsp;while(&lt;FILE&gt;)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;if(/$search_term/i)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;$found_match 

1;<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;if(/&lt;TITLE&gt;/)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;chop;<BR>&nbsp;&nbsp;&nbsp;&nbsp;$title 
= $_;<BR>&nbsp;&nbsp;&nbsp;&nbsp;$title =~ 
s/&lt;TITLE&gt;//g;<BR>&nbsp;&nbsp;&nbsp;&nbsp;$title =~ 
s/&lt;\/TITLE&gt;//g;<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;if($found_match)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;push(@found_set, 
$file);<BR>&nbsp;&nbsp;&nbsp;if($title eq 
"")<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;$Title{$file} = 
$file;<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;else<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;$Title{$file} 

$title;<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;close(FILE);<BR>&nbsp;&nbsp;print 
"&lt;P&gt;\n";<BR>&nbsp;}<BR>&nbsp;closedir(DIR);<BR>}</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV></BODY></HTML>