title: Perl: Return hash from subroutine
body: <p>I have been trying examples for hours but I can't seem to grasp how to do what I want to do.</p>
  
  <p>I want to return a hash from a subroutine, and I figured a reference was the best option. Here's where it gets a bit tricky. I want to reference a hash like $hash{$x}. I am still a noob at perl :/</p>
  
  <p>1.First question, the examples I use seem to show it is ok to use $hashTable{$login}, should I be using %hashTable{$login} or does it not matter? Below is the code:</p>
  
  <pre><code>sub authUser  {
      $LocalPath = "/root/UserData";
      open(DATAFILE, "&lt; $LocalPath");
      while( $linebuf = &lt;DATAFILE&gt; ) {
          chomp($linebuf);
          my @arr = split(/:/, $linebuf);
          my $login = $arr[1];        # arr[1] contains the user login names
          my $hashTable{ $login } = "$arr[0]";        #$arr[0] is account number
      }
      close DATAFILE;
      return \$hashTable{ $login };
  }
  </code></pre>
  
  <p>I then want to test this data to see if a login is present, here is my test method</p>
  
  <pre><code># test login Dr. Brule which is present in UserData
  my $test = "Dr. Brule";
  my $authHash = &amp;authUser();
  
  if ( $authHash{ $test } )  {
      print "Match for user $test";
  }
  else  {
      print "No Match for user $test";
  }
  </code></pre>
  
  <p>2.Should my $authHash be really $authHash{ $something }, I am so confused on this</p>
  
  <p>Edit: After some reading tips, still attempting but no dice, any help would be greatly appreciated</p>
  
  <p><hr>
  Edit 2: Can anyone modify my code so that I can understand the answers better? I'm sorry I can't seem to get this to work at all, I have been trying for hours and I really want to know the correct way to do this, I can post my various tries but I feel that will be a waste of real estate.</p>