Tutorials Point


  Perl Home

  PERL Functions

© 2011 TutorialsPoint.COM


  Home     References     About TP     Advertising  

PERL eof Function



Syntax

eof FILEHANDLE

eof()

eof


Definition and Usage

  • 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.

Return Value

  • undef if FILEHANDLE is not at end of file

  • 1 if FILEHANDLE will report end of file on next read

Example

Following are the 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
    }


Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names