lua-users home
lua-l archive

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


I'm pretty new but it looks like no one's responded. It seems to me what you want to do is this:


local data = assert(io.open("C:\places.txt","r"))
if (data) then
	for line in data:lines() do
	...
else
	doError()
end


Dave Collins
Front-End Engineer
Mercatus Technologies Inc.
60 Adelaide Street East, Suite 700
Toronto ON M5C 3E4
T  416 603 3406 x 298
F  416 603 1790

dave.collins@mercatustechnologies.com
www.mercatustechnologies.com


-----Original Message-----
From: lua-l-bounces@lists.lua.org [mailto:lua-l-bounces@lists.lua.org] On Behalf Of Gilles Ganault
Sent: Sunday, July 24, 2011 8:56 AM
To: lua-l@lists.lua.org
Subject: [5.1.4] "attempt to index global 'data' (a nil value)

Hello

Using a Lua script on XP, I need to open an HTML file and extract
hyperlinks...
===========
data = io.open("C:\places.txt","r") 
for line in data:lines() do 
      for token in string.gmatch(line, '<a
href="(/places/.+?\.php)">') do 
              print(token) 
      end 
end 
data:close()
===========

... but it fails with the following error message:
===========
lua5.1.exe: places.lua:2: attempt to index global 'data' (a nil value)
===========

Any idea what is wrong with the above?

Thank you.