|The stupid question is the question not asked|
help with SEEK, TELL, READ, othersby Kozz (Friar)
|on Jun 29, 2000 at 04:55 UTC||Need Help??|
Kozz has asked for the
wisdom of the Perl Monks concerning the following question:
Most wise monks:
I'm having some difficulties. I want to open a file for read/write and immediately obtain an exclusive lock, read the whole thing into a scalar (or array), do something with the data I read, then write it all back to the file (clobbering whatever was once there), then close it. But how do I do all this? I thought I saw a good explanation in a post a week ago, but I couldn't find the post. And I also tried reading the manpages, but was unable to decipher all the functions. Perhaps I'm missing something.
Here's what I've got:
So the problem is that this seems to leave me with an empty file, rather than reading and then writing what I had. Perhaps I'm intermixing some seek/read/truncate calls incorrectly or something. In addition, if I simply want to read the entire file into the scalar using read(), how would I do that, since I don't know the length (in bytes) to ask for? Honestly, I did read some man pages for read, seek, truncate, tell, but I must be missing something, or making a blatantly obvious mistake.
Any help you can provide is much appreciated.