|Keep It Simple, Stupid|
Re: Catching errors in closing lexical filehandlesby Zaxo (Archbishop)
|on Sep 27, 2004 at 05:43 UTC||Need Help??|
As far as I know, you can't [Added: There is a way, see my other reply below, You *Can* Catch errors in closing lexical filehandles]. Observe,
prints '1', the result of printing to the filehandle.
Placing an explicit close after the print statement gives something like,
That uses the handy /dev/full device of linux, for which writes always fail with ENOSPC. The failure would have occurred on print if we had set $fh to autoflush or had printed more than a buffersworth of text.
For careful error handling, you should close your lexical handles as if they didn't know how to do it for themselves.
Update: gaal++ points out an error. Corrected.