John W.Krahn <[EMAIL PROTECTED]> writes: > use Fcntl ':seek'; > > seek FILE, -100, SEEK_END or die "Cannot seek on './myfile' $!";
Still seeing something I don't understand. Using a working version of the code I posted (included at the end) telling seek to go to 100 bytes before the byte count at eof. I see a small discrepancy in where it actually goes of 5-15 bytes. I didn't use Fcntl ':seek' because it appears to lack the other two operators (SEEK_SET, SEEK_CUR) referred to at perldoc -f seek. And it seems like what I really needed was SEEK_SET or (zero 0) as shown at perldoc -f seek. Since using SEEK_END or (2) will give an unpredictable seeking location because the amount of data entered will vary every time (a real working version) of this script gets used. So subtracting the original end of file byte cnt + 100 may not go where we want to be. Seems like it would be better to tell seek to go to 100 bytes before the original end of file byte count. So I had that wrong originally too. That is what I'm attempting here but as mentioned above it appears to show an additional offset of 12 bytes from somewhere: OS? Im running Gentoo linux, cat ./testseek.pl ===== * ===== * ===== * ===== * ===== #!/usr/local/bin/perl use strict; use warnings; # use Fcntl ':seek'; my $bytes; open(FILE,"+>>./myfile")or die " Can't open ./myfile: $!"; ## Grab the total byte count in this file $bytes = tell(FILE); print "Pre seek bytes <$bytes> \n\n"; sleep 2; print 'We print line\nline\nline\nline\nto ./myfile' . "\n"; print FILE "line\nline\nline\nline\n"; print "Now we subtract 100 from <$bytes>:Getting:" . ($bytes - 100) . "\n"; print 'Setting seek(FILE, ' . ($bytes - 100) . ', 0)' . "\n\n"; ## go back to 100 bytes before pervious end of file (in bytes). ## Didn't use Fcntl ':see'; because it appears to lack the SEEL_SET or ## SEEK_CUR refered to at perldoc -f seek seek(FILE, ($bytes - 100) ,0); sleep 4; while(<FILE>){ print tell(FILE) . ': Showing bytes per line using tell()' , "\n"; } close(FILE); ===== * ===== * ===== * ===== * ===== > wc -c myfile 137 myfile > ./testseek.pl Pre seek bytes <137> We print line\nline\nline\nline\nto ./myfile Now we subtract 100 from <137>:Getting:37 Setting seek(FILE, 37, 0) 49: Showing bytes per line using tell() 50: Showing bytes per line using tell() 51: Showing bytes per line using tell() 62: Showing bytes per line using tell() 86: Showing bytes per line using tell() 88: Showing bytes per line using tell() 110: Showing bytes per line using tell() 111: Showing bytes per line using tell() 123: Showing bytes per line using tell() 137: Showing bytes per line using tell() 142: Showing bytes per line using tell() 147: Showing bytes per line using tell() 152: Showing bytes per line using tell() 157: Showing bytes per line using tell() -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/