in reply to How to erase the file content
From the question, it really sounds to me that the file is already open, and that the OP doesn't want to close it and re-open it. In which case, they are looking for truncate.
open my $fh, ">", "./foo.txt" or die( "Couldn't etc." ); print $fh "$_\n" for 1..100; truncate $fh, 0; print $fh "$_\n" for 1..10; close $fh;
Now foo.txt contains 1..10 only.
Update: As parv mentioned up-thread, this might close and re-open under the hood. It's not clear if you don't want to re-open for programatic reasons or for performance reasons.
|
|---|