Connecting Tech Pros Worldwide Forums | Help | Site Map

a hash of arrays

Newbie
 
Join Date: Dec 2007
Posts: 7
#1: Dec 21 '07
Hi all,
I'm having a problem getting the length of an array that I've put in a
hash here's my code

Expand|Select|Wrap|Line Numbers
  1. $voorwaardehash{$key} = [@getallen];
  2.  
  3.         @lengte = $voorwaardehash{$key};
  4.  
  5.         print "--".$#lengte ."\n";
now this looks fine to me except that ik keeps returning 0 instead of the true length of the array thats at the key

KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#2: Dec 21 '07

re: a hash of arrays


Quote:

Originally Posted by adriaan

Hi all,
I'm having a problem getting the length of an array that I've put in a
hash here's my code

Expand|Select|Wrap|Line Numbers
  1. $voorwaardehash{$key} = [@getallen];
  2.  
  3.         @lengte = $voorwaardehash{$key};
  4.  
  5.         print "--".$#lengte ."\n";
now this looks fine to me except that ik keeps returning 0 instead of the true length of the array thats at the key


You need to use dereferencing syntax because $voorwaardehash{$key} is a reference to an array:

@lengte = @{ $voorwaardehash{$key} };
print scalar @lengte;

or:

print scalar @{ $voorwaardehash{$key} };

or:

$length = @{ $voorwaardehash{$key} };
print $length;
Newbie
 
Join Date: Dec 2007
Posts: 7
#3: Dec 22 '07

re: a hash of arrays


thanx the @{} thing was what I was looking for
Reply