perl-5.38.0
sysseek FILEHANDLE,POSITION,WHENCE

Sets FILEHANDLE's system position in bytes using lseek(2). FILEHANDLE may be an expression whose value gives the name of the filehandle. The values for WHENCE are 0 to set the new position to POSITION; 1 to set it to the current position plus POSITION; and 2 to set it to EOF plus POSITION, typically negative.

FILEHANDLE のシステム位置を バイト単位lseek(2) を使って設定します。 FILEHANDLE は、実際のファイルハンドル名を与える式でもかまいません。 WHENCE の値が、0 ならば、新しい位置を POSITION の位置へ設定します; 1 ならば、現在位置から POSITION 加えた位置へ設定します; 2 ならば、 EOF から POSITION だけ(普通は負の数です)加えた位置へ、新しい位置を 設定します。

Note the emphasis on bytes: even if the filehandle has been set to operate on characters (for example using the :encoding(UTF-8) I/O layer), the seek, tell, and sysseek family of functions use byte offsets, not character offsets, because seeking to a character offset would be very slow in a UTF-8 file.

バイト単位に対する注意: 例え(例えば :encoding(UTF-8) I/O 層を使うなどして) ファイルハンドルが文字単位で処理するように設定されていたとしても、 seek, tell, sysseek シリーズの関数は 文字オフセットではなくバイトオフセットを使います; 文字オフセットでシークするのは UTF-8 ファイルではとても遅いからです。

sysseek bypasses normal buffered IO, so mixing it with reads other than sysread (for example readline or read), print, write, seek, tell, or eof may cause confusion.

sysseek は普通のバッファ付き IO を バイパスしますので、 sysread 以外の (例えば readlineread の)読み込み、 print, write, seek, tell, eof と混ぜて使うと混乱を引き起こします。

For WHENCE, you may also use the constants SEEK_SET, SEEK_CUR, and SEEK_END (start of the file, current position, end of the file) from the Fcntl module. Use of the constants is also more portable than relying on 0, 1, and 2. For example to define a "systell" function:

WHENCE には、Fcntl モジュールで使われている SEEK_SET, SEEK_CUR, SEEK_END (ファイルの先頭、現在位置、ファイルの最後)という定数を 使うこともできます。 定数の使用は 0, 1, 2 に依存するよりも移植性があります。 例えば "systell" 関数を定義するには:

    use Fcntl 'SEEK_CUR';
    sub systell { sysseek($_[0], 0, SEEK_CUR) }

Returns the new position, or the undefined value on failure. A position of zero is returned as the string "0 but true"; thus sysseek returns true on success and false on failure, yet you can still easily determine the new position.

新しい位置を返します; 失敗したときは未定義値を返します。 位置がゼロの場合は、"0 but true" の文字列として返されます; 従って sysseek は成功時に真を返し、 失敗時に偽を返しますが、簡単に新しい位置を判定できます。