Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

close

Closes a filehandle, flushing any buffered output.

Closes the filehandle and releases its resources from the global FILEHANDLE_TABLE. For in-memory filehandles (opened against a scalar reference), the accumulated buffer is written back to the target variable. For pipe filehandles, the child process’s stdin is closed and waitpid is called; $? is set to the child’s exit status.

Both lexical ($fh) and bareword (FH) filehandle forms are supported. The standard handles STDIN/STDOUT/STDERR are recognized by name.

Returns 1 on success, undef on failure.

Synopsis

close($fh) or die "Cannot close: $!";
close(FH);

See Also

open, eof, $?