in reply to Can't write to open writeable Filehandle

Ellhar:

Put "__END__" on a line just before your first foreach statement. Does it then create the file with a single line in it? If not, you need to look at permissions, quota (does Windows support quotas?), ACL, etc. I don't see anything (in a very cursory scan) in your program that might cause this behavior, which is why I suspect environmental--rather than code--issues.

roboticus

Replies are listed 'Best First'.
Re^2: Can't write to open writeable Filehandle
by Ellhar (Novice) on May 09, 2008 at 11:20 UTC
    Hi Roboticus, Yes thoes lines get printed in the file if I add _END_. What does that mean? THanks for the quick reply EllHar
      Ellhar:

      If I had to guess, I'd suspect that your program is taking a long time to execute, and you're not letting it run to completion. Instead, you might be monitoring the file size and worry .... "Hmmph! My program isn't doing anything. Perhaps it's in an infinite loop?" and killing it. Since it hasn't written anything to the file, it remains empty.

      If that's the case, then you're probably suffering from buffering and should turn buffering off on the output file so that each line is written to the output file as it's printed in your program.

      ...roboticus

      Update: I guess I could've mentioned a couple of solutions... You could pepper your code with calls to flush (e.g. SUMMARY->flush() to write the output to disk immediately. But then you'd have to use IO::Handle; at the start of your program and manually insert all those calls. A better way would be to tell the filehandle to flush itself on every print/write statement. You can do this by adding SUMMARY->autoflush(); just after your open statement. You'll still need the use IO::Handle; at the beginning though. Read perldoc perlvar for more details.

        All Hail the Monks! Thanks Roboticus. Have set autoflush for the file and it currently filling nicely thankyou. Haven't come across that before but will know for next time. Ell