From: Peter Bailey Date: 2006-09-28T05:34:07+09:00 Subject: Re: problem with ".scan" Robert Klemme wrote: > Peter Bailey wrote: >>> >> Thanks a lot, -a! I've cleaned up my code. But, if you notice way >> above, I've got a File.read in the line before the file scan. If I do >> an "end" for the file scan, my "read" is still open, right? Meaning, >> I can still do stuff to the open file. > > If you're referring to your original code, then no. You use > File.read(name) > which returns the whole file in a single string. No open connection is > returned. > > Btw, for efficiency reasons if your files are large you might consider > using > > File.foreach(file_name) do |line| > .... > end > > Or use File.readlines instead of File.read - that way you get an array > with > lines and not the whole file in one piece. > > Kind regards > > robert Thanks, Robert. I'll look into that line-by-line technique. The reason I probably haven't used it is that I often need to search for or accommodate data that spans over multiple lines. -- Posted via http://www.ruby-forum.com/.