lua-users home
lua-l archive

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

My 2c

I do Q&Ds daily, mostly in VBA-Excel, like:
Excel VBA - sort 100,001 lines text file - oops, can only manage 65536, sorry
Sub do_sort()
    Dim start, finish, elapsed
    start = Now()
     ActiveSheet.Range("A1:N65536").Sort Key1:=Sheets(1).Range("A1"), Header:=xlYes
    finish = Now()
    elapsed = finish - start
    MsgBox "sorted in " & Format(elapsed, "##.#####") & " secs"
End Sub ' do_sort

Lua - sort 100,001 lines text file
local x = os.clock()                   
local lines = {}                       
for line in io.lines() do lines[#lines + 1] = line end       
for _, l in ipairs(lines) do io.write(l, "\n") end       
print(string.format("Sorted %d lines in =  %.2f seconds\n", #lines, os.clock() -x))

Lua sorted the whole file in 0.55 seconds. In an admin situation, we seldom come across files with more than 10000 rows. So, am I going to learn Lua to do this?  Well, yes, at least a bit of it, if I need to sort big files, and don't want to pay for Office 2007, and OO Calc also cannot import this whole file.

In this instance Lua was a lifesaver, but I could just as easily have used Ruby.  As for Excel and VBA, the code above was not used - this was a legacy file with line feeds that Excel could not import no matter what I tried.  So I have to say Lua won hands down here - sheer simple usefulness.

Having said this, and despite that I believe I could handle nearly every admin "funny" that comes my way using just Lua and Penlight, the thought of figuring out what went wrong after "require" (again) has me wondering about Assembler, which its adherents say (don't they all) has fewer gotchas than C. 

When all is said and done, though, looking at the code above, VBA just looks "pidgin" to me.

Jasper Cook