From: Robert Klemme Date: 2007-11-24T02:37:08+09:00 Subject: Re: Checking File for a line 2007/11/23, Dejan Dimic : > On Nov 23, 1:08 pm, Robert Klemme wrote: > > 2007/11/23, Lee Jarvis : > > > > > Peter Loftus wrote: > > > > Im pretty sure this will work but is there any cleaner way to do it? > > > > > File.readlines('file.txt.).each do |line| > > > puts 'got it!' if line =~ /regexp/ > > > end > > > > This is more efficient - no need to load the whole file into mem to > > find a single line: > > > > File.foreach "file.txt" do |line| > > if /rx/ =~ line > > puts "found it" > > break > > end > > end > > > > Cheers > > > > robert > > > > -- > > use.inject do |as, often| as.you_can - without end > > Check out > > ri IO:foreach > ri IO#each > > and use what more suits your needs. I am not sure I understand this posting of yours. Are you talking to the OP or to me? If you are talking to me, foreach is what I used in the example above. robert -- use.inject do |as, often| as.you_can - without end