Here

close WRITE_FH;
your program closes the file, but here
select WRITE_FH;
the output filehandle for print(...) was redirected to the now closed FH. Use  print $write_fh ... or print WRITE_FH ... or reset the output back to STDOUT using select *STDOUT; (or backup/restore the previous filehandle from the initial select() if it was not the standard output).

Update: I would suggest not to use select unless you might have to redirect output of some other modules (which are not under your control or you wouldn't want to mess with). Instead, please use - as you've already done in the second part - the three argument open with a lexically scoped (my $write_fh ...) variable.
Disadvantage: more typing (print $write_fh ...).
Advantages: Intent is made clear. Mixes well with regular output. Automatic close when $write_fh goes out of scope. No interference with other modules that might use select, etc.


In reply to Re: print() on closed filehandle WRITE_FH by Perlbotics
in thread print() on closed filehandle WRITE_FH by TonyNY

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.