I'm writing a program that uses a hashref tree to store data. I'm just playing around with this, so it's nothing critical. I remember reading that you could use a string to specify a variable name or something similar. I have the following string value:
my $node = "$data->{computer}->{test}->{item1}->{text}";
This wouldn't be using a string for a variable name, it would be using a string to hold a variable name, some keys and a little syntax or using a sting to hold some Perl code.
You could always eval() it to get the answer, but I seriously doubt that's called for, by what I understood of the problem description.
More simply, you could get the answer by removing the quotes in the line.
Hash keys are already strings, that's why we use them when we need this kind of functionality. It's much preferred over soft references (strings as variable names). You gather all the keys you need for the above and walk the tree to get the answer, right?
Perhaps I didn't understand the problem well. Try telling us again what you are trying to do, please.
which corresponds to the the hash tree:
my $data = {computer => {test => {item1 => {text => "computer.test.item1"}}}};
How can I get it to print "computer.test.item1" (from hash tree above) instead of just the bare string contents of $node?
print $data->{computer}{test}{item1}{text}, "\n";
Again, I don't think I understood the problem well. Try us again...
James
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>