Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

file::find usage with apache question

by Yoshiro (Novice)
on May 08, 2012 at 11:25 UTC ( #969419=perlquestion: print w/ replies, xml ) Need Help??
Yoshiro has asked for the wisdom of the Perl Monks concerning the following question:

Greetings Monks

I am stuck with another problem working with server. I'm making a cgi script to search for a word in html files located within my server file structure.

Im using the xampp 1.7.7 running Apache. In my htdocs directory i created a new one called 'myDir' in which i will have a few html files. I am trying to create a cgi script in which i use file::find. I read the cpan article and i understand that since i'm doing the search in one specific directory i need to replace the @directories_to_search array with just my directory name so it looks like this:

 find(\&wanted, '/myDir/');

The problem is that when i use the full disk path the script finds the files but not when i use the short localhost path as shown below:

 find(\&wanted, 'C:/xampp/htdocs/myDir/');

examples below don't find anything, as the variable $File::Find::name doenst return anything

 find(\&wanted, '/myDir/');  find(\&wanted, 'http://localhost/myDir/');  find(\&wanted, 'http://localhost/htdocs/myDir/');

Thank you in advance,

Yoshiro

Comment on file::find usage with apache question
Select or Download Code
Re: file::find usage with apache question
by Corion (Pope) on May 08, 2012 at 11:29 UTC

    http://localhost/myDir/ simply is not a directory name on your file system, which is why File::Find fails. HTTP and file systems are different - I recommend to learn the difference and use the approach that you already found, using the absolute directory name.

      Thank you for your reply Corion,

      I understand now, i did some reading and found out about documentroot on Apache. Seems the way i did it specifying the full path is good.

      My mistake is that i was creating the link badly using just the $File::Find::name variable. Instead now use the $_ to create a good HTTP address or could extract $DocumentRoot from $File::Find::name if there are more subdirectories in 'myDir', again to create valid HTTP addresses.

      Thank you for pointing it out to me.

      Yoshiro

      One thing to add: it should be possible to use a relative pathname, but that would be 'myDir', not '/myDir'. Starting a pathname with a slash makes it an absolute pathname, so it looks for myDir in the root filesystem (whatever that means on Windows; maybe C:\myDir?). A relative pathname is looked for inside your current working directory, so if your CGI runs from C:/www/htdocs, then passing 'myDir' to find() should cause it to look in C:/www/htdocs/myDir.

      If that doesn't work, you'll need to figure out in what current working directory your CGI does run. Or use chdir to switch to the right directory before calling find(). Or use the absolute pathname, as Corion pointed out and you've already discovered works fine.

      Aaron B.
      Available for small or large Perl jobs; see my home node.

        Your approach assumes that the "current working directory" is predictable. It usually isn't, so using absolute path names eliminates one more point of guesswork when debugging a (new) server environment.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://969419]
Approved by moritz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2014-08-20 11:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (111 votes), past polls