Skip to main content
formatting
Source Link
Mark Byers
  • 843.3k
  • 202
  • 1.6k
  • 1.5k

input file looks like:

dog,white,male cat,purple,female rat,gray,male


dog,white,male
cat,purple,female
rat,gray,male

and i want to go through and do things with that data, line by line.

File.open("animals.csv")
  while file has next line
    currentline = array with each cell being an entry in the array
    if currentline[0] == dog
      put "dogs are cool"
    end
    put "your animal is a " + currentline[0]
  end

You get the idea, right? I want to manipulate data line with ifs and whatnot and print it all out at the end.

Thanks

input file looks like:

dog,white,male cat,purple,female rat,gray,male

and i want to go through and do things with that data, line by line.

File.open("animals.csv")
  while file has next line
    currentline = array with each cell being an entry in the array
    if currentline[0] == dog
      put "dogs are cool"
    end
    put "your animal is a " + currentline[0]
  end

You get the idea, right? I want to manipulate data line with ifs and whatnot and print it all out at the end.

Thanks

input file looks like:


dog,white,male
cat,purple,female
rat,gray,male

and i want to go through and do things with that data, line by line.

File.open("animals.csv")
  while file has next line
    currentline = array with each cell being an entry in the array
    if currentline[0] == dog
      put "dogs are cool"
    end
    put "your animal is a " + currentline[0]
  end

You get the idea, right? I want to manipulate data line with ifs and whatnot and print it all out at the end.

Thanks

Source Link
sway
  • 373
  • 2
  • 5
  • 17

How do I, line by line, turn a csv into an array using Ruby?

input file looks like:

dog,white,male cat,purple,female rat,gray,male

and i want to go through and do things with that data, line by line.

File.open("animals.csv")
  while file has next line
    currentline = array with each cell being an entry in the array
    if currentline[0] == dog
      put "dogs are cool"
    end
    put "your animal is a " + currentline[0]
  end

You get the idea, right? I want to manipulate data line with ifs and whatnot and print it all out at the end.

Thanks