[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Equivalent to scanf()?
- From: KHMan <keinhong@...>
- Date: Wed, 14 Nov 2007 16:16:09 +0800
Arturo Amaldi wrote:
> I am a relative newbie with regards to Lua. I am missing dearly the
> presence of a scanf() facility -- 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.
As a Lua user, I'm glad I never have to touch scanf ever again.
:-) Read and validate is always safer, I think.
Try using line iteration like the ref manual says:
for line in io.lines(filename) do <body> end
for line in file:lines() do <body> end
Or something similar. Then use regular expressions to parse the
line, perhaps using string.gmatch or something like that. A simple
regex would be "[^,]+".
> I am grateful for any pointers you could give me.
--
Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia