From: Brian Candler Date: 2008-12-25T19:44:22+09:00 Subject: Re: newbie qusetion: read a file and print out same file unknown wrote: > $ cat input4 > car > tree > house > candy bar > paper > ocean > $ ./test56.rb > car > > tr > ee > house > candy bar > > paper > > ocean Interesting output, especially the split 'tree'. To see what's going on, I added an extra line to your code: inputFile = File.readlines("input4", 'r') p inputFile This gives the following output: ["car", "\ntr", "ee\nhouse\ncandy bar", "\npaper", "\nocean\n"] To understand what's happening here, read the documentation under "ri IO::readlines" ---------------------------------------------------------- IO::readlines IO.readlines(name, sep_string=$/) => array ------------------------------------------------------------------------ Reads the entire file specified by _name_ as individual lines, and returns those lines in an array. Lines are separated by _sep_string_. a = IO.readlines("testfile") a[0] #=> "This is line one\n" So, the problem is that the 'r' is not the file input mode, but the separator character! The fact you had the words "car", "bar" and "paper" (all ending in 'r') made this rather unclear. It looks like it's mostly splitting at the end of a line, but actually it's splitting after a letter 'r'. -- Posted via http://www.ruby-forum.com/.