SuzuBell has asked for the wisdom of the Perl Monks concerning the following question:

How can I determine the number of values for a particular key in a hash? For example:
my %HoA; for my $key ( keys %HoA ) { // gives me the correct first value in this key my $value = $HoA{$key}[0]; // does not give me the correct number of values in this key my $size = length($HoA{$key}); }
  • Comment on Is it possible to determine the number of values for a particular hash key?
  • Download Code

Replies are listed 'Best First'.
Re: Is it possible to determine the number of values for a particular hash key?
by state-o-dis-array (Hermit) on Oct 24, 2013 at 15:03 UTC
      Thank you.
Re: Is it possible to determine the number of values for a particular hash key?
by toolic (Bishop) on Oct 24, 2013 at 15:08 UTC
    length
    perldoc -f length
    This function cannot be used on an entire array or hash to find out how many elements these have. For that, use "scalar @array" and "scalar keys %hash", respectively.
Re: Is it possible to determine the number of values for a particular hash key?
by pajout (Curate) on Oct 25, 2013 at 09:20 UTC
    Strictly spoken, number of values for a particular key in a hash is 0 or 1. Of course, if the value is reference to array, that array could have many values.