Returning Hash Tables in Perl

Hi:

Does anybody know how to return hash tables created in a function?

I have something like so:

%a_hash_table = build_a_hash_table();

sub build_a_hash_table
{
my(%hash_table);

\#some code to build hash table: "%hash_table" for e.g

return %hash_table;

}

----> This unfortunately doesn't seem to work. The hash table in the main doesn't equal the one I create in the sub routine. Any insight would be greatly appreciated. Thank you!

:confused:

The "return" function can only return a reference to an array. So, I think you would have to do something like:

$a_hash_table = build_a_hash_table();

# your hash is now in %$a_hash_table
# (the hash pointed to by the $a_hash_table scalar)

# print the hash
while ( ($k, $v) = each %$a_hash_table ) {
print "$k => $v\n";
}

sub build_a_hash_table
{
my(%hash_table);
#some code to build hash table: "%hash_table" for e.g
return (\%hash_table);
}