Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Is it possible to determine the number of values for a particular hash key?

by SuzuBell (Acolyte)
on Oct 24, 2013 at 14:56 UTC ( [id://1059490]=perlquestion: print w/replies, xml ) Need Help??

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1059490]
Approved by Athanasius
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2024-04-20 06:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found