ruby - How do I find the percent complete when parsing a file? -
how can print percentage of file have parsed. parsing text file, use:
file.each_line is there method each_with_index available use strings?
this how use each_with_index find percentage complete:
amount = 10000000 file.each_with_index |line, index| if index == amount break end print "%.1f%% done" % (index/(amount * 1.0) * 100) print "\r"
get lines upfront, display progress perform whatever operation need on them.
lines = file.readlines amount = lines.length lines.each_with_index |line, index| if index == amount break end print "%.1f%% done" % (index/(amount * 1.0) * 100) print "\r" end
Comments
Post a Comment