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);

Implementation Notes

perl5: pp_sys.c — close(FH) or close() (default STDOUT).

See Also

PP runtime: close | open, eof, $?