close

close FILEHANDLE
closeThis function closes the file, socket, or pipe associated with
FILEHANDLE after flushing any IO buffers. It
closes the currently selected filehandle if the argument is omitted. It
returns true if the close is successful, false otherwise. You don’t have
to close FILEHANDLE if you are immediately
going to do another open on it, since
the next open will close it for you,
but then you would miss any error that occurred. (See open.) However, an explicit close on an input file resets the line counter
($.); the implicit close done by
open does not.
FILEHANDLE may be an expression whose
value can be used as an indirect filehandle (either the real filehandle
name or a reference to anything that can be interpreted as a filehandle
object).
If the filehandle came from a piped open, close returns false if any underlying syscall
fails or if the program at the other end of the pipe exited with nonzero
status. In the latter case, the close
forces $! ($OS_ERROR) to zero. So if a close on a pipe returns a nonzero status,
check $! to determine whether the
problem was with the pipe itself (nonzero value) or with the program at
the other end (zero value). In either event, $? ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access