It appears to me that this partial code that is in a loop. Every time you hit open FH, '>', "$list.tmp" that will start a new file with zero length. If $newline happens to be "null", nothing will be written to this file. It could be that your program for whatever reason is "tripping" over this open statement again.

A more normal order of things would be to open the output file much earlier. The reason for this is that we don't want to do a lot processing only to find out later that we can't write the result because we don't have the correct file permissions or path! I have seen programs bomb after 2-5 days of running because of this! So bad idea.

If your program doesn't run for a "long time", I see no reason the close the file handle, FH. When your Perl program exits, the OS will close that file handle. You can open a new file with the same File Handle and the OS will "recycle it". No problem. Anyway if your program just uses a couple of file handles and runs for some seconds or minutes, there is no need to "close" the file which releases some resources back to the OS.

There will be at MOST one line in your FH output file. Open this file handle earlier.


In reply to Re: Not printing to file, but print to screen ok by Marshall
in thread Not printing to file, but print to screen ok by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.