Hi,
How can i clear the contents of a file in perl?
Hi,
How can i clear the contents of a file in perl?
By "clear" I take it you mean that you want to truncate the file to zero size.
In that case...
Opening a file for writing (as opposed to appending) means you will overwrite anything in aready in the file, so writing zero-length data to the file leaves you with a zero-length file, wiping out out everything that was there.
e.g.
open FH, ">", $filename;
print FH;
close FH;