"Relm" <relm / 3tlk.net> schrieb im Newsbeitrag
news:Pine.LNX.4.21.0406160005160.25645-100000 / frieza...
> On Tue, 15 Jun 2004, Robert Klemme wrote:
>
> > "Sven Schott" <sven_schott / compnow.com.au> schrieb im Newsbeitrag
> > news:CBD4166F-BE86-11D8-B72B-000A9571732E / compnow.com.au...
> > > I was actually just about to ask that. This was how I did it(pretty
> > > much the same way as yours).
> > >
> > > file = File.open("file.csv", "r")
> > > arr =[]
> > > file.each { |i| arr << i.chomp.split(/\t/) }
> >
> > This can be nicely done with a one liner:
> >
> > arr = File.open("file.csv") {|io| io.inject([]) {|a, line| a <<
> > line.chomp.split(/\t/)} }
>
> #inject is somewhat scary...

Power often scares people...  You can implement virtually all methods in
Enumerable by using #inject.  It's great!  :-)

>   arr = File.open("file.csv") {|io|
>     io.map {|line| line.chomp.split(/\t/)}
>   }

Yes, and you can even squeeze that in one line, too. :-)

Regards

    robert