CARVIEW |
- #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; and2
to set it to EOF plus POSITION, typically negative.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), theseek
,tell
, andsysseek
family of functions use byte offsets, not character offsets, because seeking to a character offset would be very slow in a UTF-8 file.sysseek
bypasses normal buffered IO, so mixing it with reads other thansysread
(for examplereadline
orread
),print
,write
,seek
,tell
, oreof
may cause confusion.For WHENCE, you may also use the constants
SEEK_SET
,SEEK_CUR
, andSEEK_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: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"
; thussysseek
returns true on success and false on failure, yet you can still easily determine the new position.
Perldoc Browser is maintained by Dan Book (DBOOK). Please contact him via the GitHub issue tracker or email regarding any issues with the site itself, search, or rendering of documentation.
The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via the Perl issue tracker, the mailing list, or IRC to report any issues with the contents or format of the documentation.