lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,

This code extracts from a file with text in columns,
use the columns contents of each line as key and count
their occurence. This is again accessible via the columns
name as listed in the table "fields" ("AAA","BBB",...).
(See explanations of my previous mail also if you like... :)

fields={
 AAA                =  {   1  ,   11 },
 BBB                =  {  13  ,   19 },
 CCC                =  {  21  ,   27 },
 DDD                =  {  29  ,   30 },
 EEE                =  {  32  ,   50 },
 FFF                =  {  52  ,   55 },
 CCC                =  {  57  ,  100 },
 DDD                =  { 102  ,  110 },
 EEE                =  { 112  ,  114 },
 FFF                =  { 116  ,  120 },
 GGG                =  { 122  ,  123 },
 HHH                =  { 124  ,  127 },
 III                =  { 128  ,  144 },
}

data={}
for i,v in pairs(fields) do 
  -- "data.txt" the columns with values
  fh=io.open( "data.txt","r" )
  index=fields[i]
  first=index[1]
  last=index[2]
  for line in fh:lines() do
    text=string.sub( line, first, last )
    if not data[i] then
        data[i]={}
    end
    data[i][text]-data[i][text] and (data[i][text]+1) or 1
  end
  io.close( fh )
end

@Tom: I will optimize the code (reading the file) later if all works! :)

When dumping the resulting table there were many high counts -- that
is: many column entries were doubled.

Now I want to reconstruct a new table from the current one and from
the textual input which links all things together, so one is able to
"ask the new table" for example "reconstruct all lines, which column
"AAA" is "17.6955 A".

But how can I link to the contents of an table entry (in C
this would be a pointer to string, in Perl I would use references)
without getting back the entry itsself? Or do I have to arrayfy the
table which is created by the code above? Or...???

Thank you very much for any help in advance!
Best regards,
mcc