misterperl has asked for the wisdom of the Perl Monks concerning the following question:
I WANT cat hello dog wally mouse old yellermy $myVar='old yeller'; my $b = 'cat $1 dog $2 mouse $myVar'; $_ 'hello sir, I am wally, the greeter'; # Use a substitution to replace the matched parts with $b s/(hello).+(wally).+/$b/;
I GET 'cat $1 dog $2 mouse $myVar'
the RHS didn't replace $1 , $2 or $myVar. How can I force this? Is there a regex flag? an "eval" somehow?
I told Gemini that our mutual approach failed, and then she suggested:
I have a paragraph with lots of substitutions of both $1 $2 etc as well as other vars like $myVar. I want everything in the block interpolated without specifics- I might even have things in the block like $h{test} or $a(indexed to element 3). (I cant seem to enter brackets here). Her answer is way too specific.s/(hello).+(wally).+/sub { $b =~ s/\$\d+/$$1/g; }/;
as always, it is greatly appreciated that you took time from your busy day to assist me!
|
---|