Skip to content

Instantly share code, notes, and snippets.

@carlobaldassi
Created April 13, 2012 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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])
@StefanKarpinski
Copy link

Why not just call it wc? Afaik, there's no name clash since the other wc is an executable.

@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