James Gray
4/24/2008 1:08:00 PM
On Apr 24, 2008, at 6:55 AM, Bil Kleb wrote:
> OK, so I can't think my way out of a paper this morning.
>
> Can I access FasterCVS#lineno while inside a foreach?
No, but you can switch to an each() iterator and get at it that way
(just as you would with an IO object):
$ cat data.csv
one
two
three
$ cat fcsv_example.rb
#!/usr/bin/env ruby -wKU
require "rubygems"
require "faster_csv"
FCSV.open("data.csv") do |csv|
csv.each do |row|
puts "#{csv.lineno}: #{row}"
end
end
$ ruby fcsv_example.rb
1: one
2: two
3: three
Hope that helps.
James Edward Gray II