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

readline

PP function for readline

Reads one or more records from a filehandle.

In scalar context, returns the next record from the filehandle (including the record separator, typically a newline). Returns undef at end-of-file. In list context, returns all remaining records.

The record separator is controlled by $/:

  • "\n" (default) – line-at-a-time mode
  • "" – paragraph mode (reads until a blank line)
  • undef – slurp mode (reads the entire file)
  • \N (reference to integer) – fixed-length record mode (reads N bytes)
  • arbitrary string – reads until that separator is found

When the STACKED flag is set, the result is assigned to the lvalue target on the stack (e.g. my $line = <$fh>).

Supports both lexical ($fh) and bareword (FH) filehandles, as well as IO::Handle / IO::File objects.

Synopsis

$line  = <$fh>;           # scalar: next line
@lines = <$fh>;           # list: all remaining lines
$line  = readline($fh);   # explicit function form

See Also

eof, read, getc, chomp