Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: multiple values for one key in hash

by Anonymous Monk
on Nov 08, 2012 at 09:14 UTC ( #1002847=note: print w/replies, xml ) Need Help??


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 (Chancellor) 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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1002847]
help
Chatterbox?
[Discipulus]: dear brother karl has "Furthermore I consider that Donald Trump must be impeached as soon as possible" in his sig
[erix]: ah, thanks Discipulus
[1nickt]: erix perhaps you could kindly point out your technique to roho and everyone will be happy.
[Discipulus]: but i'm also animalist, so i' hirted by 1nickt's sig: The way forward always starts with a mammal test... grin..
[erix]: I might if I did remember. It's probably somewhere in the site docs
[uhClem]: I don't favor that sort of thing around here but the place for our politics is wherever we live.
[uhClem]: And besides, the objection to it was off-topic.
[Discipulus]: 1nickt hide signature is a positive action; i think is not a solution here

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (12)
As of 2017-06-22 12:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (519 votes). Check out past polls.