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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use a variable as substitution text in a perl regex

Status
Not open for further replies.

grinny

Programmer
Aug 2, 2005
1
NL
Hi,

I have a hash of variables with the name of the variable as key. Now I have some strings that can contain a $-sign followe d by a variable name. I would like to have the variables replaced with their values. I've tried the following with no succes:

$value =~ s/\$([a-z.]+)/$db[$1]/g;

Does anyone know how to do this?
 
you are using [] (for arrays) when you should be using {} (for hashes) as Trojan showed you:

$db[$1]

should be :

$db{$1}
 
Nitpick: There's no need for the /e on the end of the regexp. $db{$1} works fine in a double-quoted string (which is what the RHS of a replacement regexp is).
 
ISHNID!
Nice to see you again!
Had to be a nitpick though (but you're right). ;-)

hehehe



Trojan.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top