lua-users home
lua-l archive

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


Hi,

Wouldn't be easier to use the "simple I/O model"?

Since size matters in this particular test it is *much* better! Below is a new version. Not submitted yet (you probably have an even shorter one up your sleeve anyway??)

--
Wim


if not arg[1] then
	print(arg[0] .. [[ infile [outfile]

sort lines from infile to outfile or to stdout if no outfile is provided.]])
	return
end

io.input(arg[1])
io.output(arg[2])  -- keeps stdout if arg[2] == nil

local lines = {}

for line in io.lines() do
	table.insert(lines, line)
end

table.sort(lines)

for _, line in ipairs(lines) do
	io.write(line, "\n")
end