The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Perl Hash Harikrishna Shell Programming and Scripting 1 06-04-2008 04:03 AM
Perl Hash Harikrishna Shell Programming and Scripting 1 06-02-2008 08:45 PM
Compression algorithm( usage of Hash tables) rvan High Level Programming 5 05-01-2008 12:09 PM
hash tables, pthread_key_create Corona688 High Level Programming 2 10-31-2005 11:45 AM
Passing Hash Tables to Subroutines mirzabhai UNIX for Dummies Questions & Answers 1 08-02-2001 01:53 PM

Closed Thread
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-19-2001
Registered User
 

Join Date: Jun 2001
Location: Toronto
Posts: 4
Stumble this Post!
Talking 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!

__________________
YaS
Forum Sponsor
  #2 (permalink)  
Old 07-19-2001
PxT's Avatar
PxT PxT is offline
Registered User
 

Join Date: Oct 2000
Location: Sacramento, CA
Posts: 909
Stumble this Post!
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);
}
Google The UNIX and Linux Forums
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:08 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0