title: Perl - need to store the column values into hash
body: <p>I want to create a hash with column header as hash key and column values as hash values in Perl.</p>
  
  <p>For example, if my csv file has the following data:</p>
  
  <pre><code>A,B,C,D,E 
  1,2,3,4,5
  6,7,8,9,10
  11,12,13,14,15 ...
  </code></pre>
  
  <p>I want to create a hash as follows:</p>
  
  <pre><code>A=&gt; 1,6,11
  B=&gt;2,7,12
  c=&gt;3,8,13 ...
  </code></pre>
  
  <p>So that just by using the header name I can use that column values. 
  Is there a way in PERL to do this? Please help me.</p>
  
  <p>I was able to store required column values as array using the following script</p>
  
  <pre><code>use strict;
  use warnings;
  
  open( IN, "sample.csv" ) or die("Unable to open file");
  my $wanted_column = "A";
  my @cells;
  my @colvalues;
  
  my $header       = &lt;IN&gt;;
  my @column_names = split( ",", $header );
  my $extract_col  = 0;
  
  for my $header_line (@column_names) {
      last if $header_line =~ m/$wanted_column/;
      $extract_col++;
  }
  while ( my $row = &lt;IN&gt; ) {
      last unless $row =~ /\S/;
      chomp $row;
      @cells = split( ",", $row );
      push( @colvalues, $cells[$extract_col] );
  }
  my $sizeofarray = scalar @colvalues;
  print "Size of the coulmn= $sizeofarray";
  </code></pre>
  
  <p>But I want to do this to all my column.I guess Hash of arrays will be the best solution but I dont know how to implement it.</p>