title: Using selectall_hashref as I would selectall_arrayref
body: <p>I'm doing some exercises to increase my Perl skills and one of them involves connecting to an SQL database, running a query, and returning the results as an array. This is what I have so far:</p>
  
  <pre><code>my $search = $_[0];
  our $dbh = DBI-&gt;connect{"dbi:mysql:dbname=database", "root", "password")
      or die $DBI::errstr;
  my $sql = $dbh-&gt;selectall_arrayref("SELECT Player from Players_Sport where Sport like '$search'")
      or die $DBI::errstr;
  my @array = map { $_-&gt;[0] } @$sql;
  $dbh-&gt;disconnect
      or warn "Disconnection failed: $DBI::errstr\n";
  return @array;
  </code></pre>
  
  <p>My next step is to change the code to return the results as a hash instead of an array, but I'm not certain how to proceed. I expect to use <code>selectall_hashref</code>, but all the online examples I've found use WHILE. I want to return the results, then create the hash as separate steps.</p>