首先,我一直在使用这个站点作为整个脚本编写过程的参考,它很棒。我很欣赏每个人都在这里的有用和知识。考虑到这一点,我有一个关于Lua中匹配(模式匹配)的问题。我正在编写一个脚本,它基本上从文件输入并将其导入到表中。我正在检查文件中的特定MAC地址,作为我正在查询的主机。Lua脚本模式匹配问题
if macFile then
local file = io.open(macFile)
if file then
for line in file:lines() do
local f = line
i, j = string.find (f, "%x+")
m = string.sub(f, i, j)
table.insert(macTable, m)
end
file:close()
end
这将文件解析成我将用于稍后查询的格式。一旦该表建成后,我运行模式匹配序列,试图通过遍历表和匹配针对当前迭代的方式从表中匹配MAC:
local output = {}
t = "00:00:00:00:00:00"
s = string.gsub(t, ":", "")
for key,value in next,macTable,nil do
a, p = string.find (s, value)
matchFound = string.sub(s, a, p)
table.insert(output, matchFound)
end
这不会返回尽管当任何输出我在Lua提示符中逐行输入它,它似乎工作。我相信变量正确传递。有什么建议么?
什么'macFile'的内容是什么? – gwell 2010-08-11 15:58:26