Am I correct ?
If I want to write to a file, it should be opened with:
open (FIL, ">$fil");
If I want to append to a file, it should be opened with:
open (FIL, ">>$fil");
But, I want to write if the file is empty or absent, and append if it not empty.
If a non-empty file is opened for writing, its contents is lost.
If an empty file is opened for appending, it gets an end-of-line on the beginning.
The following script does the right thing:
#!/usr/local/bin/perl -w
my $fil = 'tonus';
-e $fil && (-s $fil) > 1 && open (FIL, ">>$fil") || open (FIL, ">$fil");
print FIL "some stuff\n";
__END__
But it seems rather awkward for such a trivial need. Is there any better ?
Thanks