Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Search and Replace

Reply
Thread Tools

Search and Replace

 
 
vspriya05@gmail.com
Guest
Posts: n/a
 
      12-06-2005
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;

 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      12-06-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote in news:1133869308.010095.175370
@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
--
A. Sinan Unur <(E-Mail Removed)>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html

 
Reply With Quote
 
 
 
 
Eric J. Roode
Guest
Posts: n/a
 
      12-06-2005
(E-Mail Removed) wrote in news:1133869308.010095.175370
@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
`$=`;$_=\%!;($_)=/(.)/;$==++$|;($.,$/,$,,$\,$",$;,$^,$#,$~,$*,$:,@%)=(
$!=~/(.)(.).(.)(.)(.)(.)..(.)(.)(.)..(.)......(.)/,$"),$=++;$.++;$.++;
$_++;$_++;($_,$\,$,)=($~.$"."$;$/$%[$?]$_$\$,$:$%[$?]",$"&$~,$#,);$,++
;$,++;$^|=$";`$_$\$,$/$:$;$~$*$%[$?]$.$~$*${#}$%[$?]$;$\$"$^$~$*.>&$=`
 
Reply With Quote
 
vspriya05@gmail.com
Guest
Posts: n/a
 
      12-06-2005
hi,

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

Thanks,
Priya

 
Reply With Quote
 
Brian Wakem
Guest
Posts: n/a
 
      12-06-2005
(E-Mail Removed) wrote:

> 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



Not working? A better explanation will be needed.


>
> $replace='\${IMAGEPATH}';
> $string="http://image.com";
>
> $string=~ s/$find/$replace/g;



$find in undefined.


--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png
 
Reply With Quote
 
Brian McCauley
Guest
Posts: n/a
 
      12-06-2005

(E-Mail Removed) wrote:

> 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}/;

 
Reply With Quote
 
Brian McCauley
Guest
Posts: n/a
 
      12-06-2005

Brian McCauley wrote:

> Or if you prefer "leaning toothpick symdrome"
>
> s/http:\/\/image.com/\\\\${IMAGEPATH}/;


Opps - one toothpick too many:

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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Losing $1 and $2 variables in my search and replace expression laredotornado@zipmail.com Perl Misc 1 06-21-2012 04:43 PM
quick and dirty registry search and replace? VB? Dave - Dave.net.nz NZ Computing 14 11-08-2004 07:44 PM
search within a search within a search - looking for better way...my script times out Abby Lee ASP General 5 08-02-2004 04:01 PM
Search and replace with NIO and Regex? Mark McKay Java 3 01-21-2004 05:29 PM



Advertisments