Q&A > Data Structures
Description:
I have the name of a variable stored in $var. How can I make it so $data grabs the variable name? I tried this:I put $$var with two $'s because one '$' for the variable, then right after that the '$var' places the variables name, I hope there's a way to do this, I'm just using bad syntax and I don't know what the procedure is called.$data = $$var;
Answer: variable through another variable contributed by Juerd That will work, but not under strict 'refs'. Symbolic references are considered bad practice (but you can't always avoid them).
Using a hash is better, and hashes are useable under strict 'refs': (You can remove quotes from hash keys that have no \W characters: $hash{testing}.) |
Answer: variable through another variable contributed by Roy Johnson Apparently this FAQ is not easy to find, since the question gets asked regularly. Re: Create an array reference from a string offers helpful input from Corion and dragonchild. |
Answer: variable through another variable contributed by metadoktor So you've done something like this? and you want to do this? now... but why would you want to do that? Unless you really meant to do this?
|
Answer: variable through another variable contributed by Roy Johnson See Re: variable with $$. |
Please (register and) log in if you wish to add an answer
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |