victorz22 has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks, I am trying to create a function that will replace an entire line in a scalar variable if a certain sub string is found. The variable contains a bunch of paths to different files and what I want to do is replace the entire line if that sub string is found. Thank you monks for your endless wisdom!
The input data looks kinda like this ___DATA___ path/to/some/file path/to/some/other/file path/to/SUBTSTRING/file #replace entire line if SUBSTRING is found path/to/file
sub scanForSubstringReplaceLine{ my($inputText, $subStringToScan, $lineReplacement) = @_; my $replacedText; $inputText =~ s/$subStringToScan/$lineReplacement/g; $replacedText = $inputText; return $replacedText; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Replacing an entire line if a substring is found
by 1nickt (Canon) on Apr 26, 2017 at 02:37 UTC | |
by huck (Prior) on Apr 26, 2017 at 03:12 UTC | |
by 1nickt (Canon) on Apr 26, 2017 at 03:27 UTC | |
by huck (Prior) on Apr 26, 2017 at 03:32 UTC | |
by victorz22 (Sexton) on Apr 26, 2017 at 06:11 UTC | |
by huck (Prior) on Apr 26, 2017 at 06:56 UTC | |
by 1nickt (Canon) on Apr 26, 2017 at 15:23 UTC | |
|
Re: Replacing an entire line if a substring is found
by kcott (Archbishop) on Apr 26, 2017 at 03:36 UTC | |
|
Re: Replacing an entire line if a substring is found
by Anonymous Monk on Apr 26, 2017 at 02:22 UTC |