Forum: Ruby on Rails Help reading csv data in a dynamic arrays w/ loops... =)

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Jeremy (Guest)
on 2006-02-13 14:51
Hi guys, I'm workin on a little ruby on rails application and I'm having
a little trouble doing something that SHOULD be pretty easy, especially
in rails... So you guys can know what I'm looking for, I included a
block of PHP code that does the job, and the block of ruby code that's
failing me :P. Thanks ahead of time to anyone who can help me out with

- - - - -
$csv_file_array = functionThatSplitsFileIntoArrayByLine("somefile.csv");

$tcount = 0;
while ( $tcount <= count($csv_file_array) ) {
  $csv_file_array[$tcount] = explode($csv_file_array[$tcount], ",");
- - - - -

After this php code, $csv_file_array should be a dynamic array where i
can access csv data. ($csv_file_array[1][3] = "First line, and the third
value (start from zero).";)

Now, here is the code im kinda on my way to using with ruby on rails. It
returns an error "index 10 out of array" so the loop's probably going on
longer than it should, i just dont get how rails handles this (no
'var++' incrementing...?)

- - - - -
task_templates = IO.readlines("somefile.csv")

tcount = 0
while tcount <= task_templates.length
  tcount = tcount.succ
- - - - -

Thanks again, hope someone can help me.
Nick S. (Guest)
on 2006-02-13 15:34
(Received via mailing list)
Even easier!

require 'csv'"mycsv.csv", "r") do |row|
    value = row[column]

Hows that?

Jeremy (Guest)
on 2006-02-13 20:46
Great, thanks alot nick!
This topic is locked and can not be replied to.