From: Daniel Harple Date: 2006-05-23T23:44:39+09:00 Subject: Re: Read File Into An Array On May 23, 2006, at 4:28 PM, bc90141 wrote: > I want to read a file into an array. I'm using the following code: > > contentsArray = Array.new > f = File.open("filenamehere") or die "Unable to open file..." > contentsArray = filenamehere.each_line { |line| } > > However, it seems to put the whole file into the array as one > item. If > I try and use contentsArray.slice! I get: > > undefined method 'slice!' for # (NoMethodError) > > So it sees the contents of the array as a file instead of a list of > text > lines as I want. contents = File.readlines("somefile") If the file does not exist Errno::ENOENT will be raised. The "or die" is not valid ruby. Try it: true or die # => true false or die # => # ~> -:2: undefined local variable or method `die' for main:Object (NameError) -- Daniel