in reply to Re^4: Scoping question - will file handle be closed?
in thread Scoping question - will file handle be closed?
Perl close() is not POSIX close(). Some less-bizarre reasons that Perl close() might fail include:
Plus there are errors that can originate from some I/O layer. You'd have to consult the documentation and/or code for whatever layers you might use for more information on that. Perhaps you can use an encoding layer configured to complain about untranslatable characters via an error return. Or a "decompress" layer might complain about invalid input.
It can be useful to check for close failing because it may be important to not continue on after close() failed because the data you were writing or reading is incomplete and so you shouldn't submit it or shouldn't mark the data source as "done" or whatever.
It is usually easier to check for close() failing than to check every single I/O operation for failure. If using buffered I/O, then checking every single I/O operation wouldn't be sufficient anyway.
If I have no logical recovery step for "incomplete data", then I will just warn when close fails.
- tye
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Scoping question - will file handle be closed? (close errors)
by BrowserUk (Patriarch) on Jul 15, 2015 at 14:53 UTC | |
by tye (Sage) on Jul 15, 2015 at 18:33 UTC |