title: Obtaining a slice through an array of hash references in Perl
body: <p>I have a Perl-related question, concerning complex data structures.  I am running version 5.8.8 of Perl on a Linux (Centos v5) server, hosting Apache.  I am interrogating a MS-SQL database.  I am using the "DBI" Perl module.</p>
  
  <p>I have a table of results from an SQL query, encoded as a reference to an array of hash references.  So each row in the table is an array element containing a hash reference, obtained using the "fetchrow_hashref" command of the DBI module.  The keys of each hash correspond to the column headings and the values corresponding to a particular cell in the table under that column heading.</p>
  
  <p>What I would like to do is to obtain an array of column data. There appear to be some methods described in the DBI documentation about how to obtain column data, but to me they are a little opaque, and it would be nice to know in general how to obtain a slice through an array of hash references as an exercise in understanding how perl referencing / dereferencing works.</p>
  
  <p>So, basically, given this:</p>
  
  <pre><code>my %datarow1 = {"firstname"=&gt; "dave", "bar"=&gt;"smith"};
  my %datarow2 = {"firstname"=&gt; "john", "bar"=&gt;"doe"};
  my %datarow3 = {"firstname"=&gt; "kim", "bar"=&gt;"kardashian"};
  </code></pre>
  
  <p>Referenced like this:</p>
  
  <pre><code>my @rows = (\%datarow1, \%datarow2, \%datarow3);
  my $rowsref=\@rows;
  </code></pre>
  
  <p>How do I get this array?:</p>
  
  <pre><code>("dave", "john", "kim")
  </code></pre>
  
  <p>I've tried this:</p>
  
  <pre><code>my @columndata=@$rowsref-&gt;[0]{"firstname"}
  </code></pre>
  
  <p>but this only gets me the first cell in the column (i.e. an array containing the one element "dave").
  There must be an elegant way of doing this in one line - if on of you perl gurus could help me out, I'd appreciate it hugely.</p>
  
  <p>Thanks</p>
  
  <p>C J</p>