I want to edit the file by adding some line and replacing some others. I am trying to work with an array that contains my file line by line, i.e.
my $output_file_string = `cat $result_dir/$file`;
my @LINES = split(/\n/, $output_file_string);
I have a hash table of strings that I want to find in the file, and either replace them, or add an extra line after them. I wrote the following code to recognize strings:
foreach my $myline (keys %{ $hFiles_added{$file} }) {
foreach my $line ( @LINES) {
if ($line =~ /\Q$myline\E/) {
}
}
}
I can’t understand how to add / replace parts and how to save the edited file back to the file (and not the array
thanks shahar
source
share