title: Read file data into array : Ruby
body: <p>All,<br>
  I have a csv file with 2 columns.I have to plot a graph based on this data. Column1(X axis) is simple incrementing numbers and column 2 has random positive integers(Y axis). A sample data looks like this</p>
  
  <p>1  95<br>
  2  95<br>
  3  95<br>
  4  85<br>
  5  81<br>
  6  81<br>
  7  84<br>
  8  92<br>
  9  85   </p>
  
  <p>I have to read the contents of the file and display it in a graph. I'm an absolute newb in Ruby. Here is the code I'm working on (not mine): </p>
  
  <pre><code>data = []
  fields = []
  csv_data = {}
  
  File.open(CSV_FILENAME, "r").each_line do |line|
    line = line.strip.split(',')
    csv_data[line.first.to_s] = line.last
  end
  
  csv_data.each do |row|
      content = row.first
    log "Creating data point: #{content}"
  
    fields &lt;&lt; content
    data &lt;&lt; row.last.to_i
  
  
  end
  </code></pre>
  
  <p>The output I see in terminal is totally different. Here is the output I see:<br>
  Creating data point: 6<br>
  Creating data point: 7<br>
  Creating data point: 8<br>
  Creating data point: 9<br>
  Creating data point: 1<br>
  Creating data point: 2<br>
  etc.  </p>
  
  <p>As result the graph is also not correct. I want the output to be in this form:<br>
  Creating data point: 1<br>
  Creating data point: 2<br>
  Creating data point: 3<br>
  etc.</p>
  
  <p>What's wrong in this piece of code?</p>