in reply to Re: Can't write to open writeable Filehandle
in thread Can't write to open writeable Filehandle

Hi Roboticus, Yes thoes lines get printed in the file if I add _END_. What does that mean? THanks for the quick reply EllHar
  • Comment on Re^2: Can't write to open writeable Filehandle

Replies are listed 'Best First'.
Re^3: Can't write to open writeable Filehandle
by roboticus (Chancellor) on May 09, 2008 at 11:32 UTC
    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