truncate

truncateFILEHANDLE,LENGTHtruncateEXPR,LENGTH
This function truncates the file opened on
FILEHANDLE, or named by
EXPR, to the specified length in bytes,
not characters. The function raises an exception if
ftruncate(2) or an equivalent isn’t implemented on
your system. (You can always truncate a file by copying the front of it,
if you have the disk space.) The function returns true on success, and
undef otherwise.
The behavior is undefined if LENGTH is
greater than the current file length. However, on traditional Unix
filesystems, it sets the length of the file past the old end, and the
kernel returns an intervening, never-written-to data as all zero
bytes.
The position in the file of FILEHANDLE
is left unchanged. You may wish to call seek before writing to the file after calling
truncate on it.
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