deMize has asked for the wisdom of the Perl Monks concerning the following question:
I was able to accomplish it by creating an external function and passing $1 as a parameter to that function, but I figure there's an easier way. Also, I was not able to create and call the inline function in one step.my $text = "Other Text. From {foo bar foo bar}"; my $pattern = 'From \{(.*?)\}'; my $replace = 'To {$1}'; $text =~ s/$pattern/$replace/ge; # text should equal "Other Text. To {foo bar foo bar }";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Pass Matched Variable into Regex Replace Variable
by Anonyrnous Monk (Hermit) on Dec 17, 2010 at 18:19 UTC | |
by deMize (Monk) on Dec 17, 2010 at 18:29 UTC | |
by Anonyrnous Monk (Hermit) on Dec 17, 2010 at 18:34 UTC | |
by deMize (Monk) on Dec 17, 2010 at 20:25 UTC | |
|
Re: Pass Matched Variable into Regex Replace Variable
by AnomalousMonk (Archbishop) on Dec 17, 2010 at 21:27 UTC |