lua-users home
lua-l archive

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


On Nov 14, 2007 9:39 AM, Arturo Amaldi <arturo.amaldi@gmail.com> wrote:
>I often have to deal with tables of
> numbers written in exponential or floating point notation, and the use
> of sscanf on a line iteration made it much easier to read in data. I
> know i could use the "*number" format but I'd rather read the file
> line by line and separate it afterwards.

Here's one way:
http://lua-users.org/wiki/GenericInputAlgorithms

For example, here is a little program to sum all the numbers in a file:

require 'func'
local s
for x in numbers() do
  s = s + x
end
print(s)

But the _verification_ issue is delicate; you could split the string
(recipes exist) and carefully call tonumber() on each of them.

steve d.