When I do that I get yet another error message:

print() on closed filehandle main::FILE at /home/Campbell/perl/Get.Info line
9

Which is what made me try ">$file" to begin with. *shrug*  

Thanks,
Campbell


-----Original Message-----
From: Andrew Nelson
To: 'Sara  Campbell Meeks'; '[EMAIL PROTECTED]'
Sent: 6/7/2001 12:39 PM
Subject: RE: Problem with getting a file to open

You can open a file via open() for reading or writing, but not both. Try


open (FILE, $file); 
print FILE; 
close(FILE); 

And see if that doesnt help. 

-----Original Message----- 
From: Sara Campbell Meeks [ mailto:[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> ] 
Sent: Thursday, June 07, 2001 12:39 PM 
To: '[EMAIL PROTECTED]' 
Subject: Problem with getting a file to open 


I have this bit of code: 

#!/usr/bin/perl -w 

$edgar = "/home/Campbell/perl/edgar" 

opendir (EDGAR, $edgar) or die "Can't find $edgar!\n"; 

while ($file = readdir EDGAR) { 
        open (FILE, ">$file"); 
        print FILE; 
} 


When I run the program I get this error message: 

Use of uninitialized value in print at /home/Campbell/perl/Get.Info line
9 

If I change the open line to say 

        open (FILE, "<$file"); 

I get this error message: 

Filehandle main::FILE opened only for input at
/home/Campbell/perl/Get.Info 
line 9 

I don't understand why it recognizes the file handle in one case and not
in 
the other, and I don't have the first clue how to fix it.  Help?  I'm
using 
perl 5.6.0 on a RedHat 7.1 machine if it means anything. 

Thanks, 
Campbell 

Reply via email to