From: John Johnson Date: 2003-04-29T00:45:20+09:00 Subject: Re: File reading and line continuation with '\' I misinterpreted your request. I thought you wanted to use \ as the line ending character. The following does what you want. Boundary conditions (last line in file ends in \, empty lines continued with \, etc.) are left as an exercise for the reader :-) Regards, JJ #!/usr/bin/env ruby def processLine(aLine) p aLine end theLine = "" File.open(ARGV[0], "r") { |inFile| inFile.each_line { |line| line.chop! if line =~ /^(.+)\\$/ theLine << $1 next else theLine << line end processLine(theLine) theLine = "" } } On Sun, 2003-04-27 at 00:18, Jim Freeze wrote: > On Sunday, 27 April 2003 at 10:11:06 +0900, John Johnson wrote: > > This should do it: > > > > File.open(in_filename, "r") { |inFile| > > inFile.each_line ("\\") { |line| > > # whatever > > } > > } > > > > Hmm... I don't get it. > > irb(main):009:0> File.open("a") { |f| > irb(main):010:1* f.each_line("\\") { |line| p line }} > "one \\" > "\ntwo \\" > "\nthree\nfour\n" > => # > > > cat a > one \ > two \ > three > four > > I was thinking I would get: > > "one two three\n" > "three\n" > "four" > > ri says: > ----------------------------------------------------------- IO#each_line > ios.each_line( aSepString=$/ ) {| line | block } -> ios > ------------------------------------------------------------------------ > Synonym for IO#each. > > What I need to match on as a sep string is /[^\\]\n$/. > I don't see how "\\" can work, but, it is after midnight > my time. > > Jim > > > > > Regards, > > JJ > > > > On Sat, 2003-04-26 at 20:39, Jim Freeze wrote: > > > Hi: > > > > > > Is there an simple way to get ruby to read lines in a file > > > ending with a backslash, '\', as a single line? > > > > > > > cat a > > > one\ > > > two > > > irb(main):001:0> a=File.read("a") > > > => "one\\\ntwo\n" > > > irb(main):002:0> b=File.readlines("a") > > > => ["one\\\n", "two\n"] > > > > > > I would like instead: > > > > > > f=File.readlines("a") > > > ["onetwo\n"] > > > > > > Thanks > > > > > > -- > > > Jim Freeze > > > ---------- > > > Positive, adj.: > > > Mistaken at the top of one's voice. > > > -- Ambrose Bierce, "The Devil's Dictionary" > > > > > > > > > > > -- > Jim Freeze > ---------- > Acquaintance, n.: > A person whom we know well enough to borrow from, but not well > enough to lend to. > -- Ambrose Bierce, "The Devil's Dictionary" >