From: christopher.j.meisenzahl@... Date: 2002-12-06T02:28:08+09:00 Subject: Re: Best way to read data? Bill, Thanks for the reply! while(line = gets) p line end I'm getting: C:\tmp>2.rb < "data.dat" C:\tmp\2.rb:1:in `gets': Bad file descriptor (Errno::EBADF) from C:\tmp\2.rb:1 Using Win2K. :-( ############ Subject: Re: Best way to read data? From: "Bill Kelly" Date: Fri, 6 Dec 2002 02:03:38 +0900 References: 57777 Hi, From: > > What's the best Ruby idiom for reading data from a data file one line at a time > so that I could run the program with something like: > my_app.rb < data.txt A way to read lines from STDIN is: while(line = gets) # do something with line end Or, to read lines from a particular file by name: IO.foreach("data.txt") do |line| # do something with line end Hope this helps, Bill Christopher J. Meisenzahl CPS, CSTE Senior Software Testing Consultant Spherion christopher.j.meisenzahl@citicorp.com