readline

readline FILEHANDLE
readlineThis is the internal function implementing the <FILEHANDLE> operator, but you can use it directly. The function reads
the next record from FILEHANDLE, which may be
a filehandle name or an indirect filehandle expression that returns
either the name of the actual filehandle or a reference to anything
resembling a filehandle object, such as a typeglob. In scalar context,
each call reads and returns the next record until end-of-file is
reached, whereupon the next call returns undef. In list context, readline reads records until end-of-file is
reached and then returns a list of records. By “record”, we normally
mean a line of text, but changing the value of $/ ($INPUT_RECORD_SEPARATOR) from its default
value causes this operator to “chunk” the text differently. Undefining
$/ makes the chunk size entire files
(slurp mode).
When slurping files in scalar context, if you happen to slurp an
empty file, readline returns "" the first time, and undef each subsequent time. When slurping from
the magical ARGV filehandle, each file returns one chunk (again, null ...
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