perl-5.38.0
syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET
syswrite FILEHANDLE,SCALAR,LENGTH
syswrite FILEHANDLE,SCALAR

Attempts to write LENGTH bytes of data from variable SCALAR to the specified FILEHANDLE, using write(2). If LENGTH is not specified, writes whole SCALAR. It bypasses any PerlIO layers including buffered IO (but is affected by the presence of the :utf8 layer as described later), so mixing this with reads (other than sysread)), print, write, seek, tell, or eof may cause confusion because the :perlio and :crlf layers usually buffer data. Returns the number of bytes actually written, or undef if there was an error (in this case the errno variable $! is also set). If the LENGTH is greater than the data available in the SCALAR after the OFFSET, only as much data as is available will be written.

write(2) を使って、指定した FILEHANDLEへ、変数 SCALAR から、LENGTH バイトの データの書き込みを試みます。 LENGTH が指定されなかった場合、 SCALAR 全体を書き込みます。 これは、バッファ付き IO ルーチンを含むどの PerlIO も通らないので (しかし、後述するように :utf8 の存在の影響を受けます)、他の入力関数、 他の入力関数 (sysread 以外), print, write, seek, tell, eof と混ぜて使うと、出力がおかしくなるかもしれません; :perlio 層と :crlf 層は普通データをバッファリングするからです。 実際に読み込まれたデータの長さか、エラー時には undef が 返されます(この場合エラー変数 $! もセットされます)。 LENGTH が OFFSET 以降の SCALAR の利用可能なデータより大きかった場合、 利用可能なデータのみが書き込まれます。

An OFFSET may be specified to write the data from some part of the string other than the beginning. A negative OFFSET specifies writing that many characters counting backwards from the end of the string. If SCALAR is of length zero, you can only use an OFFSET of 0.

OFFSET を指定すると、SCALAR の先頭以外の場所から、 データを取り出して、書き込みを行なうことができます。 OFFSET に負の値を指定すると、文字列の最後から逆向きに数えて 何バイト目から書き込むかを示します。 SCALAR の長さが 0 の場合、OFFSET は 0 のみ使用できます。

WARNING: If the filehandle is marked :utf8, syswrite will raise an exception. The :encoding(...) layer implicitly introduces the :utf8 layer. Alternately, if the handle is not marked with an encoding but you attempt to write characters with code points over 255, raises an exception. See binmode, open, and the open pragma.

警告: ファイルハンドルが :utf8 であるとマークが付けられていると、 syswrite は例外を投げます。 :encoding(...) 層は暗黙に :utf8 層を導入します。 または、もしハンドルにエンコーディングが記録されていない状態で 255 を超える符号位置の文字を書き込もうとすると、例外が発生します。 binmode, open, open プラグマを参照してください。