I want to edit a file by adding some line and replacing some others. I\'m trying to work with an array that contains my file line by line, i.e
my $outpu
Use splice to alter the contents of @LINES
.
Use open and print to write @LINES
back to your file.
If other people might be editing this file at the same time then you'll need flock.
If performance isn't that important to you then you might look at Tie::File.
For more complicated file handling, you might want seek and truncate.
But this is all covered well in the Perl FAQ - How do I change, delete, or insert a line in a file, or append to the beginning of a file?
By the way, your first two lines of code can be replaced with one:
my @LINES = `cat $result_dir/$file`;