Perl Programming/Keywords/sysseek

From Wikibooks, open books for an open world
Jump to navigation Jump to search
Previous: sysread Keywords Next: system

The sysseek keyword[edit | edit source]

The sysseek sets the file handle position in bytes by using lseek(2) of UNIX. The FILEHANDLE can also an expression that evaluates to the filehandle. WHENCE can have the values 0 to set the POSITION in bytes, 1 so that it is set to the current position plus POSITION, and 2 to set it to EOF plus POSITION.

sysseek returns the new position on success and undef otherwise. For performance reasons, even if the FILEHANDLE has been set to operate on characters, the function tell() will return the byte offsets.

Do not use sysseek with reads other than sysread, eof, print, seek, tell, or write, as it bypasses normal buffered I/O.

For WHENCE, the constants SEEK_SET, SEEK_CUR, and SEEK_END should be used for portability reasons instead of 0. 1. or 2.

Syntax[edit | edit source]


Examples[edit | edit source]

use Fcntl 'SEEK_CUR';
sysseek($_[0], 0, SEEK_CUR);

See also[edit | edit source]

syscall sysopen sysread sysseek system syswrite
Previous: sysread Keywords Next: system