Movatterモバイル変換


[0]ホーム

URL:


functions /eof
(source,CPAN)
You are viewing the version of this documentation from Perl 5.26.3.View the latest version
#eof FILEHANDLE
#eof ()
#eof

Returns 1 if the next read on FILEHANDLE will return end of fileor if FILEHANDLE is not open. FILEHANDLE may be an expression whose value gives the real filehandle. (Note that this function actually reads a character and thenungetcs it, so isn't useful in an interactive context.) Do not read from a terminal file (or calleof(FILEHANDLE) on it) after end-of-file is reached. File types such as terminals may lose the end-of-file condition if you do.

Aneof without an argument uses the last file read. Usingeof() with empty parentheses is different. It refers to the pseudo file formed from the files listed on the command line and accessed via the<> operator. Since<> isn't explicitly opened, as a normal filehandle is, aneof() before<> has been used will cause@ARGV to be examined to determine if input is available. Similarly, aneof() after<> has returned end-of-file will assume you are processing another@ARGV list, and if you haven't set@ARGV, will read input fromSTDIN; see"I/O Operators" in perlop.

In awhile (<>) loop,eof oreof(ARGV) can be used to detect the end of each file, whereaseof() will detect the end of the very last file only. Examples:

# reset line numbering on each input filewhile (<>) {    next if /^\s*#/;  # skip comments    print "$.\t$_";} continue {    close ARGV if eof;  # Not eof()!}# insert dashes just before last line of last filewhile (<>) {    if (eof()) {  # check for end of last file        print "--------------\n";    }    print;    last if eof();     # needed if we're reading from a terminal}

Practical hint: you almost never need to useeof in Perl, because the input operators typically returnundef when they run out of data or encounter an error.

Perldoc Browser is maintained by Dan Book (DBOOK). Please contact him via theGitHub issue tracker oremail regarding any issues with the site itself, search, or rendering of documentation.

The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via thePerl issue tracker, themailing list, orIRC to report any issues with the contents or format of the documentation.


[8]ページ先頭

©2009-2026 Movatter.jp