in reply to Printing a line only if first line of file
I think you confused some people You want to know, how do you print a line to the file if the file doesn't exist already? I think the following does what you are asking, you could remove the new lines and make it one line if you wanted but I wouldn't recommend it.
unless -e $file { open( my $fh, '>', $file) or die "Failed to open '$file': $!"; print $fh "Header"; }
Update: If you use IO::All then you could do 'Header' > io('test.txt') unless -e 'test.txt';
|
|---|