Perl Bug 7 - seek doesn't work in an >> append
I open a file to append, then try to seek() to the beginning of the file:
--------------------------------------------------
open(FILE,">>some_file") || die("Fie!\n");
print "Position: ",tell(FILE),"\n";
seek(FILE,0,0);
print "Position: ",tell(FILE),"\n";
print FILE "Should be on the first line\n";
close(FILE);
--------------------------------------------------
The seek() doesn't do anything, though the tell() claims that it did.
(Run this a few times and look at "some_file" and watch the tell() values)
UPDATE: Evidently this isn't a bug, the print ignores the location
and prints to the bottom of the file. According to MJD:
On your Linux system, opening a file in append mode means that the
system automatically seeks the pointer to the end immediately prior to
each write. See the man page for open(2) for details:
O_APPEND
The file is opened in append mode. Before each
write, the file pointer is positioned at the end
of the file, as if with lseek. ...