Здравствуйте, я начинающий с lua и пытаюсь перебрать CSV по одной строке за раз. Я хотел бы сохранить каждую строку, прочитанную из CSV, в хэш-таблице. Текущее состояние экспериментального кода выглядит следующим образом: -
local fp = assert(io.open ("fields.csv"))
local line=fp:read()
local headers=ParseCSVLine(line,",")
-- for i,v in ipairs(headers) do print(i,v) end -- this print outs the CSV header nicely
-- now read the next line from the file and store in a hash
local line=fp:read()
local cols=ParseCSVLine(line,",")
local myfields={}
for i,v in ipairs(headers) do
-- print( v,cols[i]) -- this print out the contents nicely
myfields[v]=cols[i] ------ this is where things go bad -----
end
for i,v in ipairs(myfields) do print(i,v) end ------ this print nothing!
ParseCSVLine из http://lua -users.org / wiki / LuaCsv . Однако проблема заключается в присвоении myfields [v]. Глядя на различные документы, синтаксис того, что разрешено в [], довольно странный, и кажется, что Lua не позволяет использовать символ здесь. Как построить мою новую таблицу в myfields?