title: Saving the output of a Perl SQL query to a hash instead of an array
body: <p>I'm trying to add an argument to the end of a command line, run that search through a MySQL database, and then list the results or say that nothing was found. I'm trying to do it by saving the query data as both hashes and arrays (these are exercises, I'm extremely new at PERL and scripting and trying to learn). However, I can't figure out how to do the same thing with a hash. I do want the SQL query to complete, and then write the output to a hash, so as not to invoke the While function. Any guidance would be appreciated.</p>
  
  <pre><code>#!/usr/bin/perl -w
  use warnings;
  use DBI;
  use Getopt::Std;
  
  &amp;function1;
  &amp;function2;
  
  if ($arrayvalue != 0) {
      print "No values found for '$search'"."\n"};
  
  sub function1 {
  
  getopt('s:');
  $dbh = DBI-&gt;connect("dbi:mysql:dbname=database", "root", "password")
      or die $DBI::errstr;
  
  $search = $opt_s;
  $sql = $dbh-&gt;selectall_arrayref(SELECT Player from Players_Sport where Sport like '$search'")
  or die $DBI::errstr;
  @array = map { $_-&gt;[0] } @$sql;
  $dbh-&gt;disconnect
      or warn "Disconnection failed": $DBI::errstr\n";
  
  }
  
  sub function2 {
  
  @array;
  $arrayvalue=();
  print join("\n", @array, "\n");
  if(scalar (@array) == 0) {
      $arrayvalue = -1
  }
      else {$arrayvalue = 0;
  };
  
  }
  </code></pre>