perl-5.38.0
close FILEHANDLE
close

Closes the file or pipe associated with the filehandle, flushes the IO buffers, and closes the system file descriptor. Returns true if those operations succeed and if no error was reported by any PerlIO layer. Closes the currently selected filehandle if the argument is omitted.

FILEHANDLE に対応したファイルまたはパイプをクローズして、 IO バッファをフラッシュし、システムファイル記述子をクローズします。 操作が成功し、PerlIO 層からエラーが報告されなかった場合に真を返します。 引数が省略された場合、現在選択されているファイルハンドルをクローズします。

You don't have to close FILEHANDLE if you are immediately going to do another open on it, because open closes it for you. (See open.) However, an explicit close on an input file resets the line counter ($.), while the implicit close done by open does not.

クローズしてすぐにまた、同じファイルハンドルに対してオープンを行なう 場合には、open が自動的に close を行ないますので、 close FILEHANDLE する必要はありません。 (open を参照してください。) ただし、明示的にクローズを行なったときにのみ入力ファイルの 行番号 ($.) のリセットが行なわれ、 open によって行なわれる 暗黙の close では行なわれません。

If the filehandle came from a piped open, close returns false if one of the other syscalls involved fails or if its program exits with non-zero status. If the only problem was that the program exited non-zero, $! will be set to 0. Closing a pipe also waits for the process executing on the pipe to exit--in case you wish to look at the output of the pipe afterwards--and implicitly puts the exit status value of that command into $? and ${^CHILD_ERROR_NATIVE}.

ファイルハンドルがパイプつきオープンなら、close は その他のシステムコールが失敗したりプログラムが非ゼロのステータスで終了した 場合にも偽を返します。 プログラムが非ゼロで終了しただけの場合は、$!0 に セットされます。 後でパイプの出力を見たい場合のために、パイプのクローズでは、パイプ上で 実行されているプロセスの終了を待ち、また自動的にコマンドのステータス値を $?${^CHILD_ERROR_NATIVE} に設定します。

If there are multiple threads running, close on a filehandle from a piped open returns true without waiting for the child process to terminate, if the filehandle is still open in another thread.

複数のスレッドがある場合、パイプで開かれたファイルハンドルに対する close は、そのファイルハンドルが他のスレッドで まだ開かれている場合、子プロセスの終了を待たずに真を返します。

Closing the read end of a pipe before the process writing to it at the other end is done writing results in the writer receiving a SIGPIPE. If the other end can't handle that, be sure to read all the data before closing the pipe.

書き込み側が閉じる前に途中でパイプの読み込み側が閉じた場合、 書き込み側に SIGPIPE が配送されます。 書き込み側がこれを扱えない場合、パイプを閉じる前に 確実に全てのデータが読み込まれるようにする必要があります。

Example:

例:

    open(OUTPUT, '|sort >foo')  # pipe to sort
        or die "Can't start sort: $!";
    #...                        # print stuff to output
    close OUTPUT                # wait for sort to finish
        or warn $! ? "Error closing sort pipe: $!"
                   : "Exit status $? from sort";
    open(INPUT, 'foo')          # get sort's results
        or die "Can't open 'foo' for input: $!";

FILEHANDLE may be an expression whose value can be used as an indirect filehandle, usually the real filehandle name or an autovivified handle.

FILEHANDLE は式でもかまいません; この場合、値は間接ファイルハンドルと して扱われ、普通は実際のファイルハンドル名か自動有効化されたハンドルです。