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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



fox5
New User

Apr 12, 2008, 8:55 PM

Post #1 of 2 (172 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


KevinR
Veteran


Apr 13, 2008, 12:26 AM

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

this is wrong:


Code
return (\$cust, \@products);


it would be:


Code
 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