From: Joda jenson Date: 2011-09-30T05:39:07+09:00 Subject: Re: IO.readlines will not accept variable with file name Why? Robert Klemme wrote in post #1024202: > On Thu, Sep 29, 2011 at 11:14 AM, Joda jenson > wrote: >> puts filearray [0] >> filename1 = ("\"/home/user/file.txt\"") >> >> It will print the Double quote but still will not work if I pass it to >> the IO.readlines() >> >> It gives a (Errno::ENOENT) >> >> It doesn't seem to matter how I doctor a string with quotes I can't get >> IO.readlines() to accept it. Only hard coding it works for some reason. > > Insert a line after "gets" like this: > > puts "what is the name of the file=>" > filename1 = gets > p filename1 # look at the output > > filearray = IO.readlines(filename) > puts filearray [0] > > You'll immediately see what's wrong. :-) > > Kind regards > > robert Robert I thought I had done that but the .inspect shows I am getting a "\n" at the end of the string. Thanks for the help on this sorry for the typo, it was really late when I was posting. What is the easiest why to get the "\n" off the end? -- Posted via http://www.ruby-forum.com/.