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

后端 未结 9 1215
自闭症患者
自闭症患者 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:19

    My modification to ghostdog74 is that file handle should in the print statements and the file should be closed after the second print statement.

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

提交回复
热议问题