Yeah, this EOF seems like a good way to go. It's addressed in some, but not all (eg, not the activestate)
perlfaq5:
"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?
.....
The following code snippet deletes the last line of a file without making a copy or reading the whole file into memory:
open (FH, "+< $file");
while ( <FH> ) { $addr = tell(FH) unless eof(FH) }
truncate(FH, $addr);"
Presumably you can modify this to do things other than deleting. Hope this helps!
Or, you could do like the most recent perlfaq5 suggests and use Tie::File:
"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 distribution since Perl 5.8.0."
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.