icon Top 9 categories map      RocketAware > Perl >

seek FILEHANDLE,POSITION,WHENCE

Tips: Browse or Search all pages for efficient awareness of Perl functions, operators, and FAQs.



Home

Search Perl pages


Subjects

By activity
Professions, Sciences, Humanities, Business, ...

User Interface
Text-based, GUI, Audio, Video, Keyboards, Mouse, Images,...

Text Strings
Conversions, tests, processing, manipulation,...

Math
Integer, Floating point, Matrix, Statistics, Boolean, ...

Processing
Algorithms, Memory, Process control, Debugging, ...

Stored Data
Data storage, Integrity, Encryption, Compression, ...

Communications
Networks, protocols, Interprocess, Remote, Client Server, ...

Hard World
Timing, Calendar and Clock, Audio, Video, Printer, Controls...

File System
Management, Filtering, File & Directory access, Viewers, ...

    
seek FILEHANDLE,POSITION,WHENCE
Sets FILEHANDLE's position, just like the fseek() call of stdio. 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). For WHENCE you may use the constants SEEK_SET, SEEK_CUR, and SEEK_END from either the IO::Seekable or the POSIX module. Returns 1 upon success, 0 otherwise.

If you want to position file for sysread() or syswrite(), don't use seek() -- buffering makes its effect on the file's system position unpredictable and non-portable. Use sysseek() instead.

On some systems you have to do a seek whenever you switch between reading and writing. Amongst other things, this may have the effect of calling stdio's clearerr(3). A WHENCE of 1 (SEEK_CUR) is useful for not moving the file position:

    seek(TEST,0,1);

This is also useful for applications emulating tail -f. Once you hit EOF on your read, and then sleep for a while, you might have to stick in a seek() to reset things. The seek() doesn't change the current position, but it does clear the end-of-file condition on the handle, so that the next <FILE> makes Perl try again to read something. We hope.

If that doesn't work (some stdios are particularly cantankerous), then you may need something more like this:

    for (;;) {
        for ($curpos = tell(FILE); $_ = <FILE>; $curpos = tell(FILE)) {
            # search for some stuff and put it into files
        }
        sleep($for_a_while);
        seek(FILE, $curpos, 0);
    }

Source: Perl builtin functions
Copyright: Larry Wall, et al.
Next: seekdir DIRHANDLE,POS

Previous: scalar EXPR



(Corrections, notes, and links courtesy of RocketAware.com)


[Overview Topics]

Up to: Stdio Stream file operations
Up to: File Access




Rapid-Links: Search | About | Comments | Submit Path: RocketAware > Perl > perlfunc/seek.htm
RocketAware.com is a service of Mib Software
Copyright 2000, Forrest J. Cavalier III. All Rights Reserved.
We welcome submissions and comments