I’m data-mining information from a website, and one of the things I must do is change a piece of information from what the page gives me into another piece of information, and turn that second piece of information into a variable. I simply cannot figure out a way to do this, however.
Given the table below:
t = {big = "tall", little = "short", fat = "wide", skinny = "thin"}
… how can I make it so when I do:
adj = string.match(page,'Adjective: (%w+)')
… and it matches big, I can return the value of tall but turn it into a table? I have tried using a function, which didn’t work, and I’m not wanting to do something like t[adj]={} because I’m not wanting to make a sub-table of t.
I feel like it’s staring me right in the face, but I’m drawing a blank.
Edit for clarification:
I know how to get the adjective that I need, or how to show the value for big, etc. What I’m talking about is the ability to do this:
- Find the value based on the adjective found. In this case,
bigwas found, the value istall. - Take the value found (again, in this case,
tall) and turn that value into its own table. Then I’d have the table from above, and a new one that hasn’t been populated with, calledtall. That way, after I populate it with information, I can call it bytall["somekeyvalue"]
Does that make a bit more sense now?
If you are not bothered with global variable, you can use the global environement table.
After getting your value (by t[adj]), you can create your table like this :
You will be able then to access to the table tall everywhere