Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

literal 2 non-literal strings

Status
Not open for further replies.

Hikeeba

Programmer
Nov 17, 2000
5
US
if i load lines from a file that have ${a} in them, how do i get perl to replace ${a} with the variable ${a}?

i know i can do: s/\${a}/${a}/g
but i want it to do ALL variables at once...any help?
 
eval doesn't work, i don't want anything happening other than variable replacement either. but i did finally figure out how to do it.

s/\${(.)}/${${1}}/g;


this replaces all instances of literal ${blahblah} with the variables value ;-)
 
What is the purpose of using {}?

From
&quot;When the bracketing construct ( ... ) is used, \<digit> matches the digit'th substring. Outside of the pattern, always use ``$'' instead of ``\'' in front of the digit. (While the \<digit> notation can on rare occasion work outside the current pattern, this should not be relied upon. See the WARNING below.) The scope of $<digit> (and $`, $&, and $') extends to the end of the enclosing BLOCK or eval string, or to the next successful pattern match, whichever comes first. If you want to use parentheses to delimit a subpattern (e.g., a set of alternatives) without saving it as a subpattern, follow the ( with a ?:.&quot;

&quot;You may have as many parentheses as you wish. If you have more than 9 substrings, the variables $10, $11, ... refer to the corresponding substring. Within the pattern, \10, \11, etc. refer back to substrings if there have been at least that many left parentheses before the backreference. Otherwise (for backward compatibility) \10 is the same as \010, a backspace, and \11 the same as \011, a tab. And so on. (\1 through \9 are always backreferences.)&quot;
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top