perl-5.38.0
eof FILEHANDLE
eof ()
eof

Returns 1 if the next read on FILEHANDLE will return end of file or 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 then ungetcs it, so isn't useful in an interactive context.) Do not read from a terminal file (or call eof(FILEHANDLE) on it) after end-of-file is reached. File types such as terminals may lose the end-of-file condition if you do.

次に FILEHANDLE 上で読み込みを行なったときに、EOF が返されるときか、 または FILEHANDLE がオープンされていないと、1 を返します。 FILEHANDLE は、値が実際のファイルハンドルを示す式であってもかまいません。 (この関数は、実際に文字を読み、ungetc を行ないますので、 対話型の場合には有用ではありません。) 端末ファイルは EOF に達した後にさらに読み込んだり eof(FILEHANDLE) を 呼び出したりしてはいけません。 そのようなことをすると、端末のようなファイルタイプは EOF 状態を失ってしまうかもしれません。

An eof without an argument uses the last file read. Using eof() 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, an eof() before <> has been used will cause @ARGV to be examined to determine if input is available. Similarly, an eof() after <> has returned end-of-file will assume you are processing another @ARGV list, and if you haven't set @ARGV, will read input from STDIN; see "I/O Operators" in perlop.

引数を省略した eof は、最後に読み込みを行なった ファイルを使います。 空の括弧をつけた eof() は異なります。 これはコマンドラインのファイルリストで構成され、<> 演算子経由で アクセスされる擬似ファイルを示すために用いられます。 通常のファイルハンドルと違って <> は明示的にオープンされないので、 <> を使う前に eof() を使うと、 入力が正常か確認するために @ARGV がテストされます。 同様に、<> が EOF を返した後の eof() は、 他の @ARGV リストを処理していると仮定し、もし @ARGV をセットしていないときは STDIN から読み込みます; "I/O Operators" in perlop を参照してください。

In a while (<>) loop, eof or eof(ARGV) can be used to detect the end of each file, whereas eof() will detect the end of the very last file only. Examples:

while (<>) ループの中では、個々のファイルの終わりを調べるには、 eofeof(ARGV) を用いるのに対して eof() は最後のファイルの終わりのみを調べます。 例:

    # reset line numbering on each input file
    while (<>) {
        next if /^\s*#/;  # skip comments
        print "$.\t$_";
    } continue {
        close ARGV if eof;  # Not eof()!
    }

    # 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
    }

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

現実的なヒント: Perl で eof が必要となることは、 ほとんどありません; 基本的には、データがなくなったときやエラーがあったときに、入力演算子が undef を返してくれるからです。