in reply to Re: file::find usage with apache question
in thread file::find usage with apache question

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.

Replies are listed 'Best First'.
Re^3: file::find usage with apache question
by Corion (Patriarch) on May 08, 2012 at 13:43 UTC

    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

        well, if you are running this in a cgi script, another possibility would be using FindBin to avoid an absolute path.
        find(..., "$FindBin::Bin/../myDir");