Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: file::find usage with apache question

by Corion (Patriarch)
on May 08, 2012 at 11:29 UTC ( [id://969421]=note: print w/replies, xml ) Need Help??


in reply to file::find usage with apache question

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.

Replies are listed 'Best First'.
Re^2: file::find usage with apache question
by aaron_baugher (Curate) on May 08, 2012 at 12:37 UTC

    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.

        Agreed, using an absolute pathname is best. The only time I'd use a relative one in a case like this were if I had already used chdir with an absolute path to switch to a particular directory that contained multiple subdirectories for different kinds of things; then I'd use relative paths to access those subdirectories.

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

        Thank you Aaron and Corion

        Aaron, I have tried at first 'myDir' without slashes but it didn't work. I realize now it was because my script was running from 'cgi-bin' so it was looking in '/cgi-bin/myDir'.

        Corion, a good observation, noted.

        Yoshiro

Re^2: file::find usage with apache question
by Yoshiro (Novice) on May 08, 2012 at 12:27 UTC

    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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://969421]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-20 01:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found