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

truncate

Truncates a file to a specified length.

Truncates the file identified by the first argument to at most LENGTH bytes. The first argument may be either an open filehandle or a filename string. When given a filename, the file is opened for writing just long enough to perform the truncation.

Returns 1 on success, undef on failure (e.g. permissions, invalid filehandle).

Synopsis

truncate($fh, $length);          # by open filehandle
truncate('/path/to/file', $len);  # by filename

See Also

open, seek, tell