[pm-h] write to empty files

Uri Guttman uri at stemsystems.com
Fri Jun 8 10:20:16 PDT 2018


On 06/08/2018 01:11 PM, rlharris at oplink.net wrote:
>
> I would prefer to use Perl to create the files with the desired headers.
> Once I know how to do that, I can make use of Perl to add additional
> file-specific material to each file, and save much time in manual editing.

File::Slurp is your friend here. it can't be easier than this:

use File::Slurp ;

write_file( 'filename', "header text\n" ) ;

that will work even on a 0 length file if it is writeable. touch should 
leave the files writeable. but with that call, you don't even need to 
have a file there in advance.

and this will add more text to the end of the file:

append_file( 'filename', "more text\nand even more\n" ) ;

uri


More information about the Houston mailing list