Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Relative path wont work when opening a file for writing

Reply
Thread Tools

Relative path wont work when opening a file for writing

 
 
skieros
Guest
Posts: n/a
 
      04-24-2007
open(FILE, ">>/some_folder/some_sub_folder/digest.passwd") or die $!;
print FILE "$user:$realm:" . Digest::MD5::md5_hex("$user:$realm:
$pass") . "\n";
close(FILE);

Hello i have the above code that i have changed from absolute hdd path
to a relative to a web server path, but after the change the file
cannot be opened.

Problem is that cause of the script runnign both in localhost and
remote server
i cant specify the same absolute path so i need some relativity here.

I could use a varibale after determiantion of *where* the scrpt is
running, that is which host, but i want to accomplish it with a
relative path. Is this possible?!

 
Reply With Quote
 
 
 
 
Mark Clements
Guest
Posts: n/a
 
      04-24-2007
skieros wrote:
> open(FILE, ">>/some_folder/some_sub_folder/digest.passwd") or die $!;
> print FILE "$user:$realm:" . Digest::MD5::md5_hex("$user:$realm:
> $pass") . "\n";
> close(FILE);
>
> Hello i have the above code that i have changed from absolute hdd path
> to a relative to a web server path, but after the change the file
> cannot be opened.
>
> Problem is that cause of the script runnign both in localhost and
> remote server
> i cant specify the same absolute path so i need some relativity here.
>
> I could use a varibale after determiantion of *where* the scrpt is
> running, that is which host, but i want to accomplish it with a
> relative path. Is this possible?!
>


It'll depend on your webserver, but something like

use strict;
use warnings;

my %paths = (
relative => q(some_folder/asdf.txt),
absolute => q(/other_path/some_folder/asdf.txt),
);
my $filepath;

if($ENV{SERVER_NAME} eq 'localhost'){
$filepath = $paths{relative};
}else{
$filepath = $paths{absolute};
}

open my $file,">>",$filepath or die $!;
 
Reply With Quote
 
 
 
 
J. Gleixner
Guest
Posts: n/a
 
      04-24-2007
Mark Clements wrote:
> skieros wrote:
>> open(FILE, ">>/some_folder/some_sub_folder/digest.passwd") or die $!;
>> print FILE "$user:$realm:" . Digest::MD5::md5_hex("$user:$realm:
>> $pass") . "\n";
>> close(FILE);
>>
>> Hello i have the above code that i have changed from absolute hdd path
>> to a relative to a web server path, but after the change the file
>> cannot be opened.


Why not? What's the error?

>>
>> Problem is that cause of the script runnign both in localhost and
>> remote server
>> i cant specify the same absolute path so i need some relativity here.
>>
>> I could use a varibale after determiantion of *where* the scrpt is
>> running, that is which host, but i want to accomplish it with a
>> relative path. Is this possible?!
>>

>
> It'll depend on your webserver, but something like
>
> use strict;
> use warnings;
>
> my %paths = (
> relative => q(some_folder/asdf.txt),
> absolute => q(/other_path/some_folder/asdf.txt),
> );
> my $filepath;
>
> if($ENV{SERVER_NAME} eq 'localhost'){
> $filepath = $paths{relative};
> }else{
> $filepath = $paths{absolute};
> }
>
> open my $file,">>",$filepath or die $!;


That's fine as long as the path exists and is writable by the user
running the process.
 
Reply With Quote
 
skieros
Guest
Posts: n/a
 
      04-27-2007
On Apr 24, 11:11 pm, "J. Gleixner" <glex_no-s...@qwest-spam-
no.invalid> wrote:
> Mark Clements wrote:
> > skieros wrote:


> >> Hello i have the above code that i have changed from absolute hdd path
> >> to a relative to a web server path, but after the change the file
> >> cannot be opened.

>
> Why not? What's the error?


Perl cannot find the file to open.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FileUpload control doesn't work (fail in client side early stages) when path is relative i.e "\\path.." Oren ASP .Net 1 04-29-2007 04:20 PM
opening a file using a relative path from a subclass in a package spike grobstein Python 5 12-07-2005 10:35 PM
How do I convert an absolute path into a relative path Nigel Wilkinson Ruby 2 07-25-2005 07:37 PM
absolute path versus relative path in JSP Matt Java 3 07-08-2004 08:31 PM
Make a relative url path from an absolute path to another one Thomas Guettler Python 3 10-27-2003 04:41 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57