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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open Directory isnt like DOORS

Status
Not open for further replies.

VspecGTR3

Technical User
Feb 3, 2003
62
US
my task is simple so i though... im trying to make a simple damn script that reads a file from a directory in the cgi-bin directory like so /cgi-bin/files
 
open (FILENAME, "files/file.db");
$stuph = <FILENAME>; #first line of file
close (FILENAME);

Just like opening a regular file but your specify it in another directory.
 
If you're reading lots of files from a specific directory, you could just change the scripts working directory to it.
Code:
chdir 'files';        #change to directory 'files'
open FILE, 'file.db'; #open 'file.db' in 'files'
chdir '..';           #change working directory back (to parent)
----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light
 
Changing directories like that could lead to problems if the files directory is a symbolic link. After the [tt]chdir '..';[/tt], you're working directory will not be what you expect it to be.
 
good call ----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light
 
Should work:
Code:
use Cwd;
my $oldDir = cwd();
chdir 'files';
open FILE, 'file.db';
chdir $oldDir;
----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top