From: Tristin Davis Date: 2008-03-10T15:22:28+09:00 Subject: Re: IO#Foreach -- Max line length Here's the benchmarks for the old and new code: Old: 5.484000 0.031000 5.515000 ( 5.782000) New: 5.094000 0.047000 5.141000 ( 5.407000) =cut module DataVerifier require 'strscan' def too_large?(buffer,max=1024) return true if buffer.length >= max false end def verify_vbl(file,frequency,max,delimiter,out,cache_size) $/=delimiter buffer='' buf='' record = 1 o = File.new(out,"w") f = File.open(file,'r') while(buffer=f.read(cache_size=1048576)) cache=StringScanner.new(buffer) while(c = cache.getch) buf << c if too_large?(buf,max) o.print "record #{record} is too long, skipping to end\n" while(x=cache.getch) if x == $/ buf='' record += 1 print "At record #{record}\n" if( (record % frequency ) == 0 ) unless frequency.nil? break end end end if c == $/ record += 1 print "At record #{record}\n" if( (record % frequency ) == 0 ) unless frequency.nil? buf = '' end end end f.close o.close record end end -- Posted via http://www.ruby-forum.com/.