[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Again problems with the creation of tables...
- From: Tom N Harris <telliamed@...>
- Date: Fri, 25 Oct 2013 15:25:23 -0400
Hello, the problem with your code is here:
> data={}
...
> data[i][text]=1
There are two things you're forgetting here. The first is that the inner table
has not been created yet. There's a shortcut (using metatables) for doing
this, but this is the long way that's easier to understand.
if not data[i] then
data[i] = {}
end
Now you can use the second subscript. To accumulate a counter is a similar
process.
data[i][text] = data[i][text] and (data[i][text] + 1) or 1
Okay, maybe not quite the same. The "THIS and THAT or SOMETHING_ELSE" is a
quick way to do an if..then..else block. It works here because the values are
all numbers.
I would advise you to change the way you loop through the file. You're code
works in column order, but the file is in row order, so you have to rewind the
file on every column which is very slow. Read each row first then read the
columns from that row into your table.
--
tom <telliamed@whoopdedo.org>