Skip to content

Instantly share code, notes, and snippets.

@carlobaldassi
Created April 13, 2012 15:14
Show Gist options
  • Save carlobaldassi/2377574 to your computer and use it in GitHub Desktop.
Save carlobaldassi/2377574 to your computer and use it in GitHub Desktop.
greedy wc test
function reallygreedylinecounter(fname::String)
f = open(fname)
return reallygreedylinecounter(f)
end
function reallygreedylinecounter(f::IOStream)
try
seek(f, 0)
end
ln = 0
eof = int(typemax(Uint32)) #argh
while (c = ccall(:ios_getc, Int, (Ptr{Void},), f.ios)) != eof
if c == '\n'
ln += 1
end
end
return ln
end
wcbasedlinecounter(fname::String) = integer(split(readall(`wc -l $fname`),' ',false)[1])
@carlobaldassi
Copy link
Author

There, I fixed it ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment