Monday, October 15, 2012
10:00 PM

Perl Script: How to seek through the file

Perl provides two functions which enable you to skip forward or backward in a file so that you can skip or re-read data.

seek - moves backward or forward
tell - returns the distance in bytes, between the beginning of the file and the current position of the file

The syntax for the seek function is:
seek (file, distance, from)

As you can see, seek requires three arguments:

file: which is the file variable representing the file in which to skip
distance: which is an integer representing the number of bytes (characters) to skip
from:which is either 0, 1, or 2

-- 0 :  the number of bytes to skip from beginning of the file.
-- 1 :  the number of bytes to skip from current location of the file.
-- 2 :  the number of bytes to skip from end of the file.

Below is simple Perl script which demonstrate the usage of seek and tell.
Continue Reading...

0 comments:

Post a Comment