Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: print() on closed filehandle WRITE_FH

by Perlbotics (Archbishop)
on Sep 25, 2018 at 18:23 UTC ( [id://1222991]=note: print w/replies, xml ) Need Help??


in reply to print() on closed filehandle WRITE_FH

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1222991]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-03-29 15:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found