title: How do I read a CSV file column by column in order to transpose it?
body: <p>I have a data set in the following format:</p>
  
  <pre><code>snp,T2DG0200001,T2DG0200002,T2DG0200003,T2DG0200004
  3_60162,AA,AA,AA,AA
  3_61495,AA,AA,GA,GA
  3_61466,GG,GG,CG,CG
  </code></pre>
  
  <p>The real data is much larger than this, extending to millions of rows and about a thousand columns. My eventual goal is to transpose this monstrosity and output the result in a text file (or CSV file or whatever, doesn't matter).</p>
  
  <p>I need to feed the data to my computer piece by piece so as not to overload my memory. I read the CSV file line by line, and then transpose it, and write to file. I then loop back and repeat the steps, appending to the text file as I go.</p>
  
  <p>The problem of course is that I am supposed to append the text file <strong>column by column</strong> instead of by row if the result is the transpose of the original data file. But a friend told me that is not feasible in Perl code. I am wondering if I can read the data column by column. Is there something similar such as the <a href="http://p3rl.org/IO%3a%3aHandle#io-getline" rel="nofollow"><code>getline</code> method</a> which I used in my original code</p>
  
  <pre><code>while (my $row = $csv-&gt;getline ($fh)) {
  </code></pre>
  
  <p>that can return columns instead of rows? Something akin to a Unix <code>cut</code> command would be preferred, if it does not require loading the entire data into memory.</p>