http://www.perlmonks.org?node_id=1002847


in reply to multiple values for one key in hash

how can i get the count of value array(multiple values are stored as an array) here?
  • Comment on Re: multiple values for one key in hash

Replies are listed 'Best First'.
Re^2: multiple values for one key in hash
by Athanasius (Archbishop) on Nov 08, 2012 at 12:49 UTC

    Just dereference the array in a scalar context:

    #! perl use strict; use warnings; my %families = (Flintstone => [ qw(Pebbles) ], Simpson => [ qw(Bart Lisa Maggie) ], Keaton => [ qw(Alex Mallory Jennifer Andy) ]); for my $name (keys %families) { my $num_children = @{ $families{$name} }; # <-- Here's where it + happens if ($num_children == 1) { print "There is $num_children child in the $name family\n"; } else { print "There are $num_children children in the $name family\n" +; } }

    Hope that helps,

    Athanasius <°(((><contra mundum