in reply to Re: Detecting Last line of a file
in thread Detecting Last line of a 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?
.....
The following code snippet deletes the last line of a file without making a copy or reading the whole file into memory:
Presumably you can modify this to do things other than deleting. Hope this helps!open (FH, "+< $file"); while ( <FH> ) { $addr = tell(FH) unless eof(FH) } truncate(FH, $addr);"
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."
|
|---|