in reply to print() on closed filehandle WRITE_FH
Here
your program closes the file, but hereclose 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).select WRITE_FH;
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.
|
|---|