I have a situation where I have a random array of variable names that I need to convert into an actual variable name because the code already references the original variable name.
I have other ways I could do this, a little more complicated code perhaps, but I was hoping there was an easy way to do it that avoids nasty code.
Here's the situation, the data is in a file like this:
$somevar = 10;
$anothervar = 20;
$thisarray{"myvar"} = 30;
$thisarray{"myvar2"} = 40;
These are read into an array and I can convert them into their actual variable names on the fly using code like this:
${"somevar"}="test";
Then you can print $somevar and it displays "test";
Easy enough to just wrap all variable names in ${} right?
Wrong.
${"thisarray{\"myvar\"}"} = 30;
That doesn't work, $thisarray{"myvar"} is blank.
Any ideas on syntax that would work?
I've tried several variations for fun, nothing worked.
This particular problem is hard to find a solution to because all of the query results about making dynamic arrays usually resolves to hash array stuff, never this.
Anyone got any ideas?