Perl file handling gone wrong?

Sam

New member
Hi, I have this code:

open FILE, ">", "$hhmmss.txt";
print FILE "$hhmmss TEXT $nick $arg\n";
close(FILE);

It gives me an error "print() on closed filehandle FILE on C:\strawberry\perl\bot.pl on line 118.". Why is that?!
 
Do you really intend to use variable $hhmmss as part of your file name in the open statement?

For test purposes change that line to use something like "testing.txt" and see what happens. Even if you get an error message always check to see if the file got created. If it did, delete it before the next test.
 
Do you have write permissions where it is trying to create the file? Add a die statement after the open

open FILE, ">", "$hhmmss.txt" or die "Could not open file\n";
 
Do you have write permissions where it is trying to create the file? Add a die statement after the open

open FILE, ">", "$hhmmss.txt" or die "Could not open file\n";
 
Back
Top