How do I pass a hash to a function in Perl?

Pass the reference instead of the hash itself. As in

PrintAA("abc", \%fooHash);

sub PrintAA
{
  my $test = shift;
  my $aaRef = shift;

  print $test, "\n";
  foreach (keys %{$aaRef})
  {
    print $_, " : ", $aaRef->{$_}, "\n";
  }
}

See also perlfaq7: How can I pass/return a {Function, FileHandle, Array, Hash, Method, Regex}?

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)