http://www.perlmonks.org?node_id=961437


in reply to Can't find relative path

Try adding this to your code:
print "<b>$_</b>: $ENV{$_}<br>\n" for sort keys %ENV;
You should see the variables SCRIPT_TRANSLATED and SCRIPT_NAME, which contain the information you need.
SCRIPT_NAME is essentially the host absolute URL (minus the scheme, host, and port) for script, and SCRIPT_TRANSLATED is the corresponding physical file.
You can extract the path from these, and use that to prefix your "data/file.txt" before opening it.

             All great truths begin as blasphemies.
                   ― George Bernard Shaw, writer, Nobel laureate (1856-1950)

Replies are listed 'Best First'.
Re^2: Can't find relative path
by Anonymous Monk on Mar 24, 2012 at 23:03 UTC
    Thanks, but the question isn't how to fix it in the code; I have several solutions for that. The question is why it's happening on this server and not on my previous (shared hosting) servers. Problem is I have a couple hundred previously-built Perl modules that expect to see a relative path, and I don't want to have to go through & rewrite them all if there's a way to fix Perl or the server to actually use the relative path.
      How about adding a symbolic link on the server, from the directory it is trying to access, to the directory where the data is ?

                   All great truths begin as blasphemies.
                         ― George Bernard Shaw, writer, Nobel laureate (1856-1950)