Apr 12, 2011

File write or append based on condition

use autodie;
use File::Copy 'copy';
my $append = ...; # If true append, else overwrite.
open my $fh, $append ? ">>" : ">", LOG;
copy "tmp", $fh;

Or:
my $append = ...; # If true append, else overwrite.
system "cat tmp " . ($append ? ">>" : ">") . " LOG" and die;