CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Sub Return A hash and an Array


New User

Apr 12, 2008, 8:55 PM

Post #1 of 2 (191 views)
Sub Return A hash and an Array Can't Post

I have a sub in a module, which return a hash and an array.

Sub getValues {


$cust{'cust_id'} = $cid;

$cust{'cust_name'} = $fullName;

$cust{'cust_cat'} = $category;

my @products = null;

push(@products, "prod_1");

push(@products, "prod_2");

return (\$cust, \@products);


when I call the sub "getValues", how can I get the hash and the array values respectively by using a proper syntax.

I tried

my ($hashValue, $product) = mypackage_name::getValues();

I can read in the array values properly, but not the hash values. the hash appears empty.

Where am I wrong? or Any idea? or Any guru can point me to the right reference?

Do appreciate your help


Apr 13, 2008, 12:26 AM

Post #2 of 2 (189 views)
Re: [fox5] Sub Return A hash and an Array [In reply to] Can't Post

this is wrong:

return (\$cust, \@products);

it would be:

 return (\%cust, \@products);

\$cust would be a reference to a non existing scalar. So change that and retry your code. Next time use "strict" and "warnings" and perl would have caught this error for you.


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives