require and do - relative vs absolute?

D

Derf

I have a file at /path/from/root/cgi-bin/file.pl

and I want to require /path/from/root/cgi-bin/dir/requirefile.pl

the web root would be /cgi-bin/file.pl and the user root would be
/path/from/root/cgi-bin/file.pl

when i use an absolute path in file.pl:

do "/path/from/root/cgi-bin/dir/requirefile.pl";

or

require "/path/from/root/cgi-bin/dir/requirefile.pl";

i get the error

Can't do: No such file or directory at /path/from/root/cgi-
bin/dir/requirefile.pl line ##.

but if I move file.pl to /path/from/root/cgi-bin/dir/file.pl

and then do a relative call:

require "requirefile.pl";

or

do "requirefile.pl";

it works fine

any ideas why?

Thanks for any help

Derf
 
B

Bob Walton

Derf said:
I have a file at /path/from/root/cgi-bin/file.pl

and I want to require /path/from/root/cgi-bin/dir/requirefile.pl

the web root would be /cgi-bin/file.pl and the user root would be
/path/from/root/cgi-bin/file.pl

when i use an absolute path in file.pl:

do "/path/from/root/cgi-bin/dir/requirefile.pl";

or

require "/path/from/root/cgi-bin/dir/requirefile.pl";

i get the error

Can't do: No such file or directory at /path/from/root/cgi-
bin/dir/requirefile.pl line ##.

but if I move file.pl to /path/from/root/cgi-bin/dir/file.pl

and then do a relative call:

require "requirefile.pl";

or

do "requirefile.pl";

it works fine

any ideas why? ....
Derf

Could maybe be because the luser your CGI script is running under (like
"nobody", perhaps?) doesn't have permissions all the way down the chain
from root?

CGI debugging is a FAQ, and, as the FAQ mentions, is also off-topic here
(your question and its answer would be the same if your script was
written in C, Befunge, etc). Please see:

perldoc -q 500
 
D

Derf

CGI debugging is a FAQ, and, as the FAQ mentions, is also off-topic here
(your question and its answer would be the same if your script was
written in C, Befunge, etc). Please see:

perldoc -q 500


it is a Perl question to me, and I only mentioned the Web factor so folks
didn't start asking me if I was stating my path from my web root or actual
root. The CGI part is really irrelevant to the problem, it happens from
command line as well. Unfortunately, this is just confusing to describe.

Derf
 
B

Bob Walton

Derf said:
@rochester.rr.com:




it is a Perl question to me, and I only mentioned the Web factor so folks
didn't start asking me if I was stating my path from my web root or actual
root. The CGI part is really irrelevant to the problem, it happens from
command line as well. Unfortunately, this is just confusing to describe.

Derf

Well, if it happens from the command line as well, it would seem only
one thing remains: your "/path/from/root/" contains a typo. Trying
that, however, reveals that the error message you claim ("Can't do: No
such file or directory at /path/from/root/cgi-bin/dir/requirefile.pl
line ##.") isn't generated by either do() or require() in the event the
specified file cannot be found. do() is silent given the code you
showed, although $! has "No such file or directory" in it; require()
generates something on the order of:

Can't locate /path/from/root/cgi-bin/dir/blah.pl in @INC (@INC contains:
C:/Perl/lib C:/Perl/site/lib .) at -e line 1.

It appears from the docs that require() won't work with an absolute path
in its input string.

Is there an "or die" clause after the do() with the error text you
mentioned?

Could you copy/paste the *exact text* of your *real error message* and
show us that? If you don't want to reveal your actual path for some
reason, set up a fake path, put the code there, generate the error, and
copy/paste the exact error, along with the results of a pwd from the
directory where the file you want to do() is.

And finally, why would you want to make the path absolute anyway? If it
is relative, then it'll still work if you move the whole shebang to a
different web server; if it's absolute, you'll probably have to modify
the path.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top