Search and Replace

V

vspriya05

Hi,

I want to replace a string with perl variable which has the
text \${IMAGEPATH}. I gave as follows. but it is not working. Can
anybody help me?

The code is

$replace='\${IMAGEPATH}';
$string="http://image.com";

$string=~ s/$find/$replace/g;
 
A

A. Sinan Unur

(e-mail address removed) wrote in @f14g2000cwb.googlegroups.com:
I want to replace a string with perl variable which has the
text \${IMAGEPATH}. I gave as follows. but it is not working. Can

It looks like you are trying to implement a templating solution. There
is no benefit to doing this from scratch: Just use one of the many
excellent templating modules, such as Template-Toolkit, HTML::Template,
Text::Template etc on CPAN.
The code is

Please do post the code you are using (reduced to a short but complete
script).
$replace='\${IMAGEPATH}';
$string="http://image.com";

$string=~ s/$find/$replace/g;

Where did $find come from? What are you specifying the g modifier?

I would have thought you would want to replace \${IMAGEPATH} with
http://image.com. What are you really trying to do?

Please read and follow the posting guidelines for this group.

Sinan
 
E

Eric J. Roode

(e-mail address removed) wrote in @f14g2000cwb.googlegroups.com:
Hi,

I want to replace a string with perl variable which has the
text \${IMAGEPATH}. I gave as follows. but it is not working. Can
anybody help me?

The code is

$replace='\${IMAGEPATH}';
$string="http://image.com";

$string=~ s/$find/$replace/g;

Characters like $ and { are special within regexes. If you want to replace
the literal string, you need to quote-escape it:

$string =~ s/\Q$find/$replace/g;

--
Eric
`$=`;$_=\%!;($_)=/(.)/;$==++$|;($.,$/,$,,$\,$",$;,$^,$#,$~,$*,$:,@%)=(
$!=~/(.)(.).(.)(.)(.)(.)..(.)(.)(.)..(.)......(.)/,$"),$=++;$.++;$.++;
$_++;$_++;($_,$\,$,)=($~.$"."$;$/$%[$?]$_$\$,$:$%[$?]",$"&$~,$#,);$,++
;$,++;$^|=$";`$_$\$,$/$:$;$~$*$%[$?]$.$~$*${#}$%[$?]$;$\$"$^$~$*.>&$=`
 
B

Brian McCauley

I want to replace "http://image.com" with \${IMAGEPATH}.

What to you mean by \${IMAGEPATH} ?

Do you mean the literal sequence backslash dolar left-brace capital-I
etc... ?

Please try to speak Perl rather than English wherever possible. (This
and much other valuable advice can be found in the posting gidelines).

s'http://image.com'\${IMAGEPATH}';

Or if you prefer "leaning toothpick symdrome"

s/http:\/\/image.com/\\\\${IMAGEPATH}/;
 
B

Brian McCauley

Brian said:
Or if you prefer "leaning toothpick symdrome"

s/http:\/\/image.com/\\\\${IMAGEPATH}/;

Opps - one toothpick too many:

s/http:\/\/image.com/\\\${IMAGEPATH}/;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top