in reply to Re^3: Replacing an entire line if a substring is found
in thread Replacing an entire line if a substring is found
Any particular reason it be to be in a single string? an array would be much easier to process and involve less character handling while doing the replacements.
use strict; use warnings; use feature 'say'; my @lines=<DATA>; for my $line (@lines) { chomp $line; if (index($line, 'SUBSTR') > -1 ) {$line='FOO'; } } #for my $line (@lines) { say $line; } my $fileContent=join("\n",@lines); say $fileContent; __DATA__ path/to/some/file path/to/some/other/file path/to/SUBSTR/file #replace entire line if SUBSTRING is found path/to/file
|
|---|