title: Data Array transferred to hash values and exporting the keys to an output file
body: <p>I have this following test data that needs to export to the format shown in my desired output with ruby programming. The real data array has 1000000 records.  </p>
  
  <pre><code>data_array1=aaaa
  data_array2=bbbb
  ----------------
  ----------------
  data_array8=hhhh , which means there are 8 data array, those have the following format :
  
  aaaa= [a,[1,2,3,4],20]
  bbbb= [b,[8,7,9,19],23]
  -----------------------
  -----------------------
  hhhh= [h,[25,26,29,30],28]
  </code></pre>
  
  <p>My desired out put needs to be exported to  text file (headers just for FYI,no need to include in the output file) :</p>
  
  <p>output.txt</p>
  
  <p>hash  tx time</p>
  
  <pre><code>a    1    20
  a    2    20
  a    3    20
  a    4    20
  b    8    25
  b    7    25
  b    9    25
  b    19   25
  ------------
  ------------
  h    25   28
  h    26   28
  h    29   28
  h    30   28
  </code></pre>
  
  <p>I am a newbie in Ruby and so far I have done this, which inconclusive:</p>
  
  <pre><code>def bhash
    1.upto(8) do |bid|
      blk=[bid]
  
      keys = %w[hash tx time ]
      data = keys.map{|key| blk[key]}
  
      hash, txids, time, difficulty = data
      CSV.open('output.txt', 'w', headers: keys, write_headers: true, col_sep: 
      "\t") do |csv|
      txids.each do |tx|
        csv &lt;&lt; [hash,tx,time]
      end
    end
  end 
  </code></pre>
  
  <p>Thanks in advance for all your help.    </p>