Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening files

Status
Not open for further replies.

Guest_imported

New member
Joined
Jan 1, 1970
Messages
0
I want to open a file in the same folder as my perl, but without using the absolute path to it. If it where a html link, it would be href=myfile.dat, so i thought fine, we'll go with open (FILE, "myfile.dat"); but for some reason.. it doesn't open the file. Can anyone tell me what i'm doing wrong?
I'm running on an ISS box not sure what perl version.
Thanks
 
Don't quote me on this, but I think that path stuff has to do with IIS, not perl because with a regular perl script, you can just put in the name of the file if it is not in another directory.


So you might be able to do some tweaking with IIS to do that, or just store the location in a variable:

[tt]
$baseloc = "C:\\location\\to\\file";
open(FILE,">>$baseloc/filename.txt") || die("failed to open file: $!");
# continue with code...
[/tt]

Any reason you don't want to have the absolute path?

Hope this helps,
-Vic
vic cherubini
vikter@epicsoftware.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash, Director
====
 
I always use the absolute path on open's and I've never had a problem. I just looked through the perldocs and I couldn't really find any info on using just the filename versus using the absolute path/filename.

Here's what I think though - I'm on Linux, and in Linux when I do a "perl -V", I get this printed for my @INC:

@INC:
/usr/lib/perl5/5.00503/i386-linux
/usr/lib/perl5/5.00503
/usr/lib/perl5/site_perl/5.005/i386-linux
/usr/lib/perl5/site_perl/5.005
.

Notice the dot at the end - Perl will look through its search path(@INC) in order - and since the dot(current directory) is listed last, then it will look in the current directory last. See if you can find out what your @INC contains - if the dot is part of your search list, then theoretically(?) you should be able to just name the file without the path and Perl should find it.

HTH,
Hardy Merrill
Mission Critical Linux, Inc.
 
You can use the $ENV{'DOCUMENT_ROOT'} variable to get the name of the root directory for your website. Then append your cgi directory and the name of the file. Ex:
Code:
$myfile = $ENV{'DOCUMENT_ROOT'}."/cgi-bin/myfile.dat";
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
i need to use an assoiative path ebcausetheprogram i'm writing is a message abord, and will be runningon various servers ihave it working betifully on the current server, but if i were toinstal it on another, i could have tomaually change all the abso paths i've put in.
i want to call one local dat file to store all the abso paths, so i can just go in and change them as and wheni need to instead of hutning through 7 perl files and doing it the hard way.I've tried using document root, .'s and stuff.. to no avail.. i think its just because of the IIS server, and is less than simple structure.
Heres to gettin myself a unix box in the not to distant :)
 
I don't know if IIS is the problem or not, but I've never had a problem using $ENV{'DOCUMENT_ROOT'} (Note: must be uppercase). Try displaying the value of that variable and see what it looks like. If you need to extract the cgi directory as well, you can use this code:
Code:
$0 =~ /^(.*)\/([^\/]+)$/;
$CgiDir = $1;
$ThisPgm = $2;
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Well if you are making a message board, I would suggest having a config.pl file that contains a variable named:

$absolutepath = "c:\\path\\to\\file\\file.dat";

And then, when the user installs the board (or gets you to), you can tell them in either a readme file or comments in the code to change the variable to suit their needs.

Hope this helps.
-Vic vic cherubini
vikter@epicsoftware.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash, Director
====
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top