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

read

Reads a fixed number of bytes from a filehandle into a scalar buffer.

Attempts to read LENGTH bytes from the filehandle FH into the scalar BUFFER. When OFFSET is supplied, data is placed at that byte position within the buffer (the buffer is null-padded if OFFSET exceeds its current length).

Returns the number of bytes actually read (which may be less than LENGTH), 0 at end-of-file, or undef on error. The target buffer is written back through lvalue targets (pad slot or stash variable).

Synopsis

$bytes = read($fh, $buf, $length);
$bytes = read($fh, $buf, $length, $offset);

See Also

sysread, readline, eof