Hi- In my Perl scripts I have a lot of variables defined like so(not necessarily fonts, this is just an example): $ver_1b= qq|<font face="verdana,arial" size="1"><b>|; What I wanted was something where I would not need to have a substitution for each variable. I used to I use something like this: $line =~ s/%%ver_1b%%/$ver_1b/g; 1 for each variable, as I knew very,very little REGEXP. Until I found this solution: $line =~ s/%%(\w+)%%/eval('$'."$1")/eg; This saved a lot of time and code. Now I have reached a point where I would like a similar solution in Javascript. Problem is the 'e' qualifier is not available in JS. And The eval function seems to work a little different. So heres what I'm using, 1 for each var. myText = myText.replace(/%%ver_2b%%/g,'<font face="verdana,arial" size="2"><b>'); Until I find a solution I'm stuck with it. Thanks- -Bill
myText.replace(/%%(\w+)%%/g, window["$1"]); And this expression, "$line =~ s/%%(\w+)%%/eval('$'."$1")/eg;", should probably be written this way. $line =~ s/%%(\w+?)%%/$$1/eg; And additionally, while this may seem like less typing, it won't lead to an efficient or maintainable system. You really want to modularize as much as you can; allow yourself the option of completely altering one aspect of the system without affecting everything else. In this case, you need to separate what the program does from the Web interface. Right now it looks like you have the script, the HTML document, and the HTML document's appearence all clumped together; changing one would inherently require you to tinker with all three.
All points well taken. My question is this: myText.replace(/%%(\w+)%%/g, window["$1"]); Is that the equivalent of my Perl formula? $line =~ s/%%(\w+?)%%/$$1/eg; -Bill