There is also a built-in function called truncate that will do what you want.
$ perl -Mstrict -Mwarnings -e ' > open my $fh, q{>}, q{rubbish} or die $!; > print $fh qq{A longish line of text\n}; > truncate $fh, 0 or die $!; > print $fh qq{Short\n}; > close $fh or die $!;' $ cat rubbish Short $
Update: Added example code.
Cheers,
JohnGG
In reply to Re^4: Empty File Contents before writing
by johngg
in thread Empty File Contnts before writing
by gautamparimoo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |