in reply to Re: Detecting Last line of a file
in thread Detecting Last line of a file

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."