From: William James Date: 2006-08-27T12:45:11+09:00 Subject: Re: No speedup...! Oliver Bandel wrote: > dblack@wobblini.net wrote: > > > Hi -- > > > > On Sat, 26 Aug 2006, William James wrote: > > > >> Oliver Bandel wrote: > >> > >>> Hello, > >>> > >>> > >>> The Code: > >>> > >>> ==================================== > >>> def look_for_begin > >>> while line = gets > >>> if line =~ /^begin/ > >>> puts line > >>> # return > >>> end > >>> end > >>> end > >>> > >>> ARGF.each { look_for_begin } > >>> ==================================== > >> > >> > >> puts ARGV.map{|f|IO.readlines(f).find{|s|s=~/^begin/}} > > > > > > Or maybe: > > > > puts ARGF.find {|s| /^begin/.match(s) } No, this only finds one instance. Mine finds the first in each file. > [...] > > Theese both things looks like if they would look for *all* > occurrnces of "begin", not the first one. You know too little of Ruby to tell what the code will do just by looking at it. Try both if you want to know what they will do. > > I also think to look only in the first 1000 lines or so... ARGV.each{|f| count = 0 IO.foreach(f) {|line| if line =~ /^begin/ print line break end count += 1 break if 1000 == count } } > > Ciao, > Oliver > > P.S.: But I now also found files, where more than one > uuencoded section was inside... > ... so, maybe reading the files complete also could make sense... > (I didn't found such files before, so I thought it would make > sense to read only until the first occurence of /^begin/)