Re: [PearlFrog] how do I use $1 in a $var for subsitutions
[In reply to]

Can't Post

Dear friend The computer never does what you want but always what you tell. See when you say

Code

$strExample =~ s/$strFind/$strReplace/;

Is it not another way of saying

Code

$strExample =~ s/This is a string./$strReplace/;

and where $strReplace is my $strReplace = 'start_\1_end';

Computer is simply doing it's job $1..$x are used to hold contents of group matches When there are no such group matches No doubt it will always print "start__end" Even as you yourself have written a good piece

Code

$strExample =~ s/(.+)/start_\1_end/;

I don't think I should post anything new over here

Quote

-For all my suggestions " I am sure someone else can do it in a better or elegant manner!"

Re: [PearlFrog] how do I use $1 in a $var for subsitutions
[In reply to]

Can't Post

PearlFrog,

Its considered rude to post a new question in another persons thread, even if they are somewhat similar. And anyway, you have the same question posted on at least one other perl forum where it has, I believe, been answered as best as possible:

My question is the exact same as cynick's question; I just gave more examples to clarify because another poster above did not seem to understand what cynick was asking, and no satisfactory answer had yet been given at the time. It would have been silly for me to start a new thread asking the same question. I was not trying to take over the thread from cynick; I was trying to get more discussion on the thread because at the time I posted there was still no solution given.

Re: [PearlFrog] how do I use $1 in a $var for subsitutions
[In reply to]

Can't Post

In Reply To

KevinR,

My question is the exact same as cynick's question; I just gave more examples to clarify because another poster above did not seem to understand what cynick was asking, and no satisfactory answer had yet been given at the time. It would have been silly for me to start a new thread asking the same question. I was not trying to take over the thread from cynick; I was trying to get more discussion on the thread because at the time I posted there was still no solution given.

Note the rather unintuitive use of double-quotes inside the single-quoted string $strReplace. And the use of "ee" on the end of the regexp to double eval the string to get it to work. Its messy. -------------------------------------------------

Re: [alex_v2] how do I use $1 in a $var for subsitutions
[In reply to]

Can't Post

In Reply To

Interesting I didn't even know you could double ee. See many years coding but a life time learning I guess.

-Alexander

Personally I try and use "e" only to run code on the replacement side of a s/// regexp, and not for trying to interpolate strings that are otherwise not interpolated. It all seems very counter-intutitve to me and seems like a good way to introduce bugs into what might be otherwise good code. But then again, maybe it just reflects my own personal limitations and shouldn't be extrapolated into anything beyond that. -------------------------------------------------