Read .csv file. Cant obtain data

Here is the code i use:

#!/usr/bin/ruby

require ‘rubygems’
require ‘csv’

ctr = 0
@data = []
CSV.foreach(‘C:/Users/nizam/test_q.csv’) do |row|
@data << row
puts “#{row[0]} | #{row[1]}”
#unless row[1] =~ /^[x]
ctr += 1
end

puts “#{ctr} rows”

puts “Hello World”

However, the output came like this:
0 rows
Hello World

Im pretty sure my .csv file has data in it. But when i run this script,
non of the data come out. I wonder why??

Thanks
Nizam

However, the output came like this:
0 rows
Hello World

Im pretty sure my .csv file has data in it. But when i run this script,
non of the data come out. I wonder why??

Can I assume since you asked another question about converting a CSV
to YAML, you were able to read your file?

require ‘csv’
=> true

CSV.foreach(‘foo.csv’) do |row|
?> p row

end
[“a”, “b”, “c”]
[“1”, “2”, “3”]
[“4”, “5”, “6”]
[“7”, “8”, “9”]

No I havnt. I can compile the script with no prob. But there is no
output. Do you know why? or maybe csv cant be read properly. I stuck
like few hours on this alone.huhu. Thanks for any help

Nizam

On 01/11/2011 06:11 PM, Kamarulnizam R. wrote:

No I havnt. I can compile the script with no prob. But there is no
output. Do you know why? or maybe csv cant be read properly. I stuck
like few hours on this alone.huhu. Thanks for any help

Nizam

Maybe you can provide a test file for people to try with your code?

-Justin

YESSSS

At last im able to read the file. It just happen. I copied the old file
and paste it into my ruby192 folder. It works!!. Attached is the i wish
to read.
Thanks for the help guys!! This forum is really helping me a lot

Nizam

At last im able to read the file. It just happen. I copied the old
file and paste it into my ruby192 folder. It works!!. Attached is the
i wish to read.
Thanks for the help guys!! This forum is really helping me a lot

Thanks! I really like helping people; but you’ve kind of upset me.

You said you are doing this for a job…

With that in mind, would you agree that you’re bloody crazy?

It would be like me putting adverts in the paper offering to sort out
people’s plumbing. I know nothing of pipes! (well… :wink:

Sir, what would you have done if no one had replied to your mails?
Jings man, you’d be buggered!

I’m not saying you’re wrong for seeking employment in the booming
CSV conversion market: oh no, no! Go right ahead.

I just think that you are completely mental.

Anyway, enough BS:

Is your client going to put their files into their ruby192 folder too?

I think you’d better think that one through, matey!