From: Paul Brannan Date: 2002-02-14T02:00:13+09:00 Subject: Re: (CSV) text file processing... On Thu, Feb 14, 2002 at 01:34:37AM +0900, Bob wrote: > I am looking for an example of (csv)text file processing. What I am > specifically after is how to take a file with a CSV format and parse > it out. This will be used with MySQL to help a customer upload a file > for an inventory and then the Ruby script will parse it and place the > values into the appropriate fields in the database. > > Any such examples out there? If you are doing very simple CSV processing, then you can use something like: File.open("foo", "r") do |input| input.each_line do |line| fields = line.split(',') do_something(fields) end end There's also a CSV library on the RAA at: http://www.ruby-lang.org/en/raa-list.rhtml?name=csv It handles input like: foo,bar,1,2,"this is a comma (,) test",more text There's a very short introduction to the library in the Ruby Developer's Guide (which also has a few chapters devoted to databases in Ruby). Paul