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

perl script suddenly stops writing to files 1

Status
Not open for further replies.

greya

Programmer
Aug 24, 2008
2
I have a script that is supposed to write output to files. It usually works fine.

Sometimes I run it and it would not write a single line to a file it is supposed to write to. Later, it would spontaneously resume working normally. E.g.

open (RESULTS, '>results.txt');
print RESULTS "BLAH";

1. always creates an empty file
2. sometimes writes "BLAH" into it, and sometimes doesn't

I tried deleting the previously created file with the same name from the directory, it did not help.

Mac OSX 10.4.11
Perl v.5.8.6

Do you have any suggestions on what can be causing this and how to fix it?

Thank you.
 
Try this:

Code:
open (RESULTS, '>results.txt') or die "Can't open file: $!";
print RESULTS "BLAH";
close (RESULTS);

run that a few times and see how it works.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
That helped. Thank you!

I guess when the script is interrupted by Ctrl+C, it causes this block some of the times. The strange thing is that even restarting the computer earlier didn't help. Thanks again.
 
The file is probably still open when you do that (Ctrl-C) and the script can't access it later. Why a restart of the computer did not clear it up seems odd though.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top