How do I add lines to the top and bottom of a file in Perl?

后端 未结 9 1135
自闭症患者
自闭症患者 2021-01-06 23:38

I want to add a line to top and bottom of the file. I can do it following way.

open (DATA, \"         


        
9条回答
  •  孤城傲影
    2021-01-07 00:04

    you can do this

    open(FILE,">", $file) or die "cannot open $file: $!";
    print FILE "add line to top\n";
    while () { print $_ ."\n";}
    close(FILE);
    print FILE "add line to bottom\n";
    

    on command line

    perl myscript.pl > newfile
    

提交回复
热议问题