victorz22 has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks, I am want to create a function to replace strings in a multi-line variable. The part I am stuck on is setting up the parse to go line by line. Thank you monks!
#Function Call my $newText = replaceText($inputText, $regex, $replacement); #Function sub replaceText{ my($inputText, my $regex, my $replacement)= @_; my $replacedText; if($inputText =~ s/$regex/$replacement/g){ $replacedText = $1; } return $replacedText; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: searching and replacing strings in a multi line variable
by huck (Prior) on Apr 20, 2017 at 22:56 UTC | |
by AnomalousMonk (Archbishop) on Apr 22, 2017 at 14:27 UTC | |
by BillKSmith (Monsignor) on Apr 22, 2017 at 03:34 UTC | |
by huck (Prior) on Apr 22, 2017 at 05:38 UTC | |
by BillKSmith (Monsignor) on Apr 22, 2017 at 10:54 UTC | |
by AnomalousMonk (Archbishop) on Apr 22, 2017 at 13:18 UTC | |
|
Re: searching and replacing strings in a multi line variable
by LanX (Saint) on Apr 20, 2017 at 22:42 UTC |