CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
Substituting, replace with var

 



godsmack
Deleted

May 18, 2001, 6:54 AM

Post #1 of 3 (3519 views)
Substituting, replace with var Can't Post

I'm having a problem, perhaps its just me, but is there a way that I can find a string, and replace it with its variable equivalent.. heres the line I'm working with

$string =~ s/(<<(.*)>>)/\$$2/is;
$string contains <<words>>, and I want it to replace <<words>> with what's in the variable $words.

Any ideas or suggestions?



japhy
Enthusiast / Moderator

May 18, 2001, 1:53 PM

Post #2 of 3 (3517 views)
Re: Substituting, replace with var [In reply to] Can't Post

You'll have to evaluate the right-hand side of the s///:


Code
s/<<(.*?)>>/"\$$1"/eeg;

First, I got rid of the useless first set of ()'s. Then, I changed .* to .*?, since using .* will match "a>> and <<b" in "<<a>> and <<b>>". Then, I fixed the right side to evaluated as a string, and then again as code. It should work for you.

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author


godsmack
Deleted

May 18, 2001, 6:39 PM

Post #3 of 3 (3513 views)
thx [In reply to] Can't Post

Thanks japhy ;-)


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives