Perl eof Function

Advertisements


Description

This function returns 1 if the next read on FILEHANDLE will return end of file, or if FILEHANDLE is not open.

An eof without an argument uses the last file read. Using eof() with empty parentheses is very different. It refers to the pseudo file formed from the files listed on the command line and accessed via the <> operator.

Syntax

Following is the simple syntax for this function:

eof FILEHANDLE

eof()

eof

Return Value

This function returns undef if FILEHANDLE is not at end of file and 1 if FILEHANDLE will report end of file on next read.

Example

Following is the example code showing its basic usage:

# insert dashes just before last line of last file
    while (<>) {
	if (eof()) {	# check for end of last file
	    print "--------------\n";
	}
	print;
	last if eof();  # needed if we're reading from a terminal
    }

When above code is executed, it produced following result:




Advertisements
Advertisements