[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: help for newbie -- make an list-table where the key is integer and the value is a hash-table-record
- From: <8rfrpp+atpm98zz5xdp4@...>
- Date: Wed, 04 Oct 2017 08:25:14 +0000
On 10/04/2017 01:58 AM, douglas mcallaster wrote:
> Would a kind soul please help me get started with a simple job task.
>
> Below job runs but returns the last record from my data file for all six lines
> in the data file.
> [...]
> for _,v in ipairs(rows)
> do local a = '_'
> local b = 0
> local c= '_'
> a,b,c= string.match (v, "(%w+)|(%d+)|(%w+)") -- parse the line
You've made my day with this formatting style!
Probably minimal change to make your code work is move "cols = {}" inside
"for _,v in ipairs(rows)" cycle:
for _,v in ipairs(rows)
do local a = '_'
local b = 0
local c= '_'
a,b,c= string.match (v, "(%w+)|(%d+)|(%w+)") -- parse the line
print (a,b,c)
cols= {} -- a hash ie nam,val -- use pairs
cols['v1']= a -- populate the hash (table)
cols['v2']= b
cols['v3']= c
-- for kc,vc in pairs (cols) do print(kc,vc) end
table.insert (dsn1, cols)
-- dsn1 [ #dsn1+1 ]= cols -- gives same result: every row in dsn1 is the last
row from input file
end
I'd highly recommend to consider snippets from Sean Conner or Russel Halley.
----
Sent using Guerrillamail.com
Block or report abuse: https://www.guerrillamail.com//abuse/?a=TVR1SAEgT70GnB36%2FGsePBvVSg%3D%3D