Name

eof

Synopsis

eof filehandle
eof(  )

Returns true if the next read on filehandle will return end-of-file, or if filehandle is not open. filehandle may be an expression with a value that gives the real filehandle name. An eof without an argument returns the end-of-file status for the last file read. Empty parentheses ( ) may be used in connection with the combined files listed on the command line. That is, inside a while (<>) loop, eof( ) will detect the end of only the last of a group of files. Use eof(ARGV) or eof (without parentheses) to test each file in a while (<>) loop. For example, the following code inserts dashes just before the last line of the last file:

while (<>) {
    if (eof(  )) {
        print "-" x 30, "\n";
    }
    print;
}

Get Perl in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.