title: Why would I return a hash or a hash reference in Perl?
body: <p>What is the most effective way of accomplishing the below? (I know they accomplish the same thing, but how would most people do this between the three, and <em>why</em>?)</p>
  
  <h3>File a.pl</h3>
  
  <pre><code>my %hash = build_hash();
  # Do stuff with hash using $hash{$key}
  sub build_hash
  {
      # Build some hash
      my %hash = ();
      my @k = qw(hi bi no th xc ul 8e r);
      for ( @k )
      {
          $hash{$k} = 1;
      }
  
      # Does this return a copy of the hash??
      return %hash;
  }
  </code></pre>
  
  <h3>File b.pl</h3>
  
  <pre><code>my $hashref = build_hash();
  # Do stuff with hash using $hashref-&gt;{$key}
  sub build_hash
  {
      # Build some hash
      my %hash = ();
      my @k = qw(hi bi no th xc ul 8e r);
      for ( @k )
      {
          $hash{$k} = 1;
      }
  
      # Just return a reference (smaller than making a copy?)
      return \%hash;
  }
  </code></pre>
  
  <h3>File c.pl</h3>
  
  <pre><code>my %hash = %{build_hash()};
  # Do stuff with hash using $hash{$key}
  # It is better, because now we don't have to dereference our hashref each time using -&gt;?
  
  sub build_hash
  {
      # Build some hash
      my %hash = ();
      my @k = qw(hi bi no th xc ul 8e r);
      for ( @k )
      {
          $hash{$k} = 1;
      }
  
      return \%hash;
  }
  </code></pre>