Cant open a file with just a relative path

S

skieros

open(FILE, ">>/somefolder/somesubfolder/digest.passwd") or die $!;
print FILE "$user:$realm:" . Digest::MD5::md5_hex("$user:$realm:
$pass") . "\n";
close(FILE);

Wehn i try to use this relative path instead of d:\www\blabla which is
absolute apache tells me it cant find the file.

Why i dotn sue an absolute path then? Because the same script will run
both on localhost and remote server and the paths are not the same, so
i need a relative path in order to work.

I could use the $ENV{'SERVER_NAME'} to determine in which host the
script runs and then set an appropriate path variable but i wan to
avoid that by using a relatiev path.
 
T

Tad McClellan

skieros said:
open(FILE, ">>/somefolder/somesubfolder/digest.passwd") or die $!;
^
^ lose this char, or put a dot in front of it
Wehn i try to use this relative path


relative paths do not start with a directory separator character.

They are relative to the current directory, hence the "relative"
in "relative path".
 
R

Randal L. Schwartz

skieros> open(FILE, ">>/somefolder/somesubfolder/digest.passwd") or die $!;
skieros> print FILE "$user:$realm:" . Digest::MD5::md5_hex("$user:$realm:
skieros> $pass") . "\n";
skieros> close(FILE);

skieros> Wehn i try to use this relative path instead of d:\www\blabla which is
skieros> absolute apache tells me it cant find the file.

This question was asked and answered on perlmonks. Please don't
repeat the same thread here.

And I find it annoying that someone posts the same question to multiple help
forums without disclosing such. It causes an unneeded waste of resources.

But, we'll always have newbies, I guess.

print "Just another Perl hacker,"; # the original
 
S

skieros

relative paths do not start with a directory separator character.

They are relative to the current directory, hence the "relative"
in "relative path".

Yes my bad.

i was trying to mention this
open(FILE, ">>somefolder/somesubfolder/digest.passwd") or die $!;

which is a relative path but still wont open th file.
 
S

skieros

This question was asked and answered on perlmonks. Please don't
repeat the same thread here.

And I find it annoying that someone posts the same question to multiple help
forums without disclosing such. It causes an unneeded waste of resources.

yes, Iam sorry, as i explained to pesonal mail i couldnt see those 2
thread on gougle groups up until today...dont know why....thats also
why i posted 2 times.
 
J

J. Gleixner

skieros said:
Yes my bad.

i was trying to mention this
open(FILE, ">>somefolder/somesubfolder/digest.passwd") or die $!;

which is a relative path but still wont open th file.

Verify that the current working directory is actually what you think it
should be.

Does the directory "somefolder/somesubfolder" exist, in the current
working directory?

Does the user running the Web server have permissions to get to that
directory?

Does the user running the Web server have permissions to write to that
directory?

Is the file writable by the user running the Web server?
 
S

skieros

Verify that the current working directory is actually what you think it
should be.

Does the directory "somefolder/somesubfolder" exist, in the current
working directory?

Does the user running the Web server have permissions to get to that
directory?

Does the user running the Web server have permissions to write to that
directory?

Is the file writable by the user running the Web server?

Wait isnt that user you describing Apache itself?!
 
S

skieros

Yes my bad.
i was trying to mention this
open(FILE, ">>somefolder/somesubfolder/digest.passwd") or die $!;
which is a relative path but still wont open th file.

Use the getcwd() function of the core Cwd module to determine your
default directory:

use Cwd;
my $cwd = getcwd();
print "current directory: $cwd\n";

Use the file text operators -e and -r to see if the file exists and is
readable by your process.

Use stat to determine the file permissions of the file in question:

my $file = '.../digest.passwd';
my @filestat = stat $file;
printf "Mode: %o\n", $filestat[2];

Print the variables $> and $< to display your effective and real user
IDs.

Good luck!

Thank you i wa having that question myself.

Iam on WinXP so do i ahve permission here like i do in linux?

And if so how can i chmod 755 <FILE_IN_QUESTION> on this OS?
 
S

skieros

Yes my bad.
i was trying to mention this
open(FILE, ">>somefolder/somesubfolder/digest.passwd") or die $!;
which is a relative path but still wont open th file.

Use the getcwd() function of the core Cwd module to determine your
default directory:

use Cwd;
my $cwd = getcwd();
print "current directory: $cwd\n";

Use the file text operators -e and -r to see if the file exists and is
readable by your process.

Use stat to determine the file permissions of the file in question:

my $file = '.../digest.passwd';
my @filestat = stat $file;
printf "Mode: %o\n", $filestat[2];

Print the variables $> and $< to display your effective and real user
IDs.

Good luck!

--
Jim Gibson


----------------------------------------------------------

----------------------------------------------------------
color]

my $file = ">>$ENV{'DOCUMENT_ROOT'}/blabla/blabla/digest.passwd";
my @filestat = stat $file;
printf "Mode: %o\n", $filestat[0], $filestat[1], $filestat[2];

returns mode 0; #dont knwo what is mode 0 though....
 
J

J. Gleixner

skieros said:
my $file = ">>$ENV{'DOCUMENT_ROOT'}/blabla/blabla/digest.passwd";
my @filestat = stat $file;
printf "Mode: %o\n", $filestat[0], $filestat[1], $filestat[2];

returns mode 0; #dont knwo what is mode 0 though....

To learn about the stat call:

perldoc -f stat

my $file = "$ENV{'DOCUMENT_ROOT'}/blabla/blabla/digest.passwd";
 
N

Nikos

Now, that's strange. Personally, I don't trust you. You post from GG,
don't you? Well, that's a real PITA, but all the times I've *had* to,
it either didn't work altogether or messages did appear quite soon at
least in their archive. Then the usual caveat about USENET articles
propagation applies. Even in this case, in PM you may have written:
"also posted in clpmisc, but the message doesn't seem to appear, will
post a reference soon."

You may dont trust me but thats the truth, i seen my 2 posts days
later in GG.
From now and on i'll post either here or imore preferably on
Perlmonks which i get more efficient answers.
 
M

Michele Dondi

Perlmonks which i get more efficient answers.

FWIW I choose where to post depending on the subject. OT posts are
discouraged in both places. But as a rough observation, ones that have
much to do with web server configuration or similar things, and very
little to do with Perl are better tolerated there, probably due to the
fact that it is a *web* based forum.


Michele
 

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,981
Messages
2,570,187
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top