Hi All
I'd like to be be able to read in some data from a file, create some variable names based on the data, assign values to these variables and then access the values assigned via the newly created variable name....sorry this is confusing. Something like this:-
File contains
abc 123
If I read in the file I'll want to create a variable name
$abcNum and assign value 123 to it. I can't just put
$abcNum = 123; , in my code because I have no way of knowing what the string on the left column could be before I read in the file.
I tried the following (Normally I would read in each line to get value of var + value but I'll just set them here for now):
$var = "abc";
my $varName = "$var" . "Num";
I then want to assign a value to this variable name. How can I do this?
The end result is that I want to have a variable called:
$abcNum with a value of "123".
I need to be able to access the value 123 via the name $abcNum (but as I say I have no way of knowing that the variable should have this name before opening my data).
Hope this makes some sense. Any help would be appreciated.
Thanks
Jules
I'd like to be be able to read in some data from a file, create some variable names based on the data, assign values to these variables and then access the values assigned via the newly created variable name....sorry this is confusing. Something like this:-
File contains
abc 123
If I read in the file I'll want to create a variable name
$abcNum and assign value 123 to it. I can't just put
$abcNum = 123; , in my code because I have no way of knowing what the string on the left column could be before I read in the file.
I tried the following (Normally I would read in each line to get value of var + value but I'll just set them here for now):
$var = "abc";
my $varName = "$var" . "Num";
I then want to assign a value to this variable name. How can I do this?
The end result is that I want to have a variable called:
$abcNum with a value of "123".
I need to be able to access the value 123 via the name $abcNum (but as I say I have no way of knowing that the variable should have this name before opening my data).
Hope this makes some sense. Any help would be appreciated.
Thanks
Jules