close#

Synopsis#

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

Description#

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.

See also#

open, eof, $?