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!

Probelms opening a file....

Status
Not open for further replies.

Guest_imported

New member
Joined
Jan 1, 1970
Messages
0
I have a file that I wish to open and read data in from.... here is my code...

$FILE = "$rfile"; #rfile is a string representing the name of the file

opendir (DIR, "/kronos/user/mrdeza/datas/") or nodir(); #open the directory where the file is

open (FILE) or die("$!, stopped");
@lines= <FILE>; #read in the desired file
close (FILE);
closedir (DIR);

Now the file is present in the given directory... and its persmissions grant readability... I just don't know what the fu#* is wrong. The error messages tell me that the file is not present. Thanks for any help, and all is appreciated.
 
I tried your code out and it works fine for me. The only thing I can think of is that $rfile is not the correct value. To debug the problem, you could read the directory and print out the files by adding the following two lines.

@files=readdir(DIR);
print &quot;@files \n&quot;;

You could also print out the $FILE variable and make sure it is the right value.

By the way, you don't have to open the directory to open the file.

Good Luck
 
Instead of assigning the file name to $FILE, the usual method of opening a file is:
Code:
open(FILE, $rfile);
Regardless, you don't really need quotes around $rfile.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top