This problem was solved. Thank you very much.
My question and the solution I am using is stated below.
Question:
open IN, "<./test.txt";
seek(IN,10,0);
read IN, $temp, 5;
seek(IN,20,0);
close(IN);
The situation is that, my handle will start at position 0.
After the first seek function, my file handle will at position 10.
After I read, my handle will at position 15.
At this moment, I seek again. Then the program will seek from the beginning or from position 20.
My question is that is there anyway for me to do searching in a file so that I do not need to search from the starting point of the file every time?
The way I am using:
use Fcntl qw(SEEK_SET SEEK_CUR SEEK_END); #SEEK_SET=0 SEEK_CUR=1 ...
$target_byte=30;
open IN, "<./test.txt";
seek(IN,10,SEEK_SET);
read IN, $temp, 5;
$position=tell(IN);
seek(IN,$target_byte-$position,SEEK_CUR);
#do what I want
close(IN);