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

Variable in variable name

Status
Not open for further replies.

CJason

Programmer
Oct 13, 2004
223
US
Is there a way to do something like this:

Code:
$a = "z";
$b$a = 10;
print "$bz\n"; # which would print 10

Thanks!
 
Cool! That worked! I also found another solution:

Code:
$a = "z";
${b.$a} = 10;
print "$bz\n"; # which would print 10

Thanks for the quick response!
 
And hopefully you don't actually do that in real code. What you probably should do is use a hash.


Code:
$a = "z";
$hash{$a} = 10;
print "$hash{'z'}\n"; # which would print 10

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Agreed, Kevin. You may or may not remember from awhile back, but I've been working on a code converter (on and off for awhile now)...and I don't have the luxury of doing everything the "right" way. I'll probably look into this hash option, however, because I agree that that is the proper/best way of doing it.

Thanks all!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top