Dejan Dimic
11/25/2007 6:10:00 PM
On Nov 24, 8:58 am, Robert Klemme <shortcut...@googlemail.com> wrote:
> 2007/11/23, Lee Jarvis <jarv...@gmail.com>:
>
> > > 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
>
> > Ahh, good point, touche my good man.
>
> While we're at it: there is another solution - probably a bit more elegant:
>
> require 'enumerator'
> File.to_enum(:foreach,"file.txt").grep(/rx/) {|li| puts li; break}
>
> :-)
>
> Kind regards
>
> robert
>
> --
> use.inject do |as, often| as.you_can - without end
That's Ruby beauty, express yourself in a way that suits you the most
and still we all can understand your dialect and enjoy.
Dima