Tie::File is probably the handiest way to do what you ask. Have you considered using something more than a flat file? The dbm interfaces that come with perl might serve. The advantage is that lookups are faster and you don't have to keep track of the physical layout in your program.
| [reply] |
Although I'm guessing at what kind of file a ".db" file is (Exim?), it looks like this question is answered in perlfaq5 - and I quote:
How do I change one line in a file/delete a line in a file/insert a
+line in the middle of a file/append to the beginning of a file?
Use the Tie::File module, which is included in the standard distri
+bution since Perl 5.8.0.
| [reply] [d/l] |
The other posters have good suggestions about updating a data file. But if you want to learn about seek, read the documentation. The second argument is the offset, and the third argument tells what to measure the offset against. The possibilities are SEEK_SET (0), SEEK_CUR (1), and SEEK_END (2). You don't really need to seek to the beginning because that is where the filehandle starts.
The end of the file is: seek($fh, 0, 2);
The beginning is: seek($fh, 0, 0);
The 10th byte from the beginning is: seek($fh, 10, 0);
The 10th byte before the end is: seek($fh, -10, 2)
| [reply] [d/l] [select] |