On Sat, Jun 16, 2001 at 04:41:48AM +0200, Louis Pouzin wrote:

> If an empty file is opened for appending, it gets an end-of-line on the
> beginning.

Opening a file for appending does not insert a newline at the beginning of
the file.  I suspect that you are creating the file in BBEdit, and have
"Force New Line at End" set in BBEdit's preferences.  The 'empty' file has
a newline in it before Perl even gets to it.


> 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 ?

open(FIL, ">>$fil") or open(FIL, ">$fil") or die "Can't open '$fil': $!\n";

Ronald

Reply via email to