Tell me the Flintstones HoH has 22 things

J

jidanni

Regarding this hash of hashes on
$ man perldsc
%HoH = (
flintstones => {
lead => "fred",
pal => "barney",
},
jetsons => {
lead => "george",
wife => "jane",
"his boy" => "elroy",
},
simpsons => {
lead => "homer",
wife => "marge",
kid => "bart",
},
);

What command will tell me what I want to know: that there are 22 things
inside it? The following docs didn't help. Does one really need to write
a recursive program to finally get a "22"? I'm willing to take 19 for an
answer too, but not 3, or "2/8".

$ perldoc -q entries
Found in /usr/share/perl/5.10/pod/perlfaq4.pod
How can I know how many entries are in a hash?
If you mean how many keys No I don't!!
$ perldoc -f length
Note that this 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.
elements==keys?!
 
S

sln

Regarding this hash of hashes on
$ man perldsc
%HoH = (
flintstones => {
lead => "fred",
pal => "barney",
},
jetsons => {
lead => "george",
wife => "jane",
"his boy" => "elroy",
},
simpsons => {
lead => "homer",
wife => "marge",
kid => "bart",
},
);

What command will tell me what I want to know: that there are 22 things
inside it? The following docs didn't help. Does one really need to write
a recursive program to finally get a "22"?

yes

-sln
 
U

Uri Guttman

LS> How you came to 22 is a bogglement ....

there are 3 top level keys (or 6 things counting keys and values) and
then 8 second level keys (16 more things) for a total of 22. yes, it is
a very odd and useless number. and it is easily derived by counting keys
recursively and doubling that value. what use this has is beyond me.

uri
 
A

A. Sinan Unur

Regarding this hash of hashes on
$ man perldsc
%HoH = (
flintstones => {
lead => "fred",
pal => "barney",
},
jetsons => {
lead => "george",
wife => "jane",
"his boy" => "elroy",
},
simpsons => {
lead => "homer",
wife => "marge",
kid => "bart",
},
);

What command will tell me what I want to know: that there are 22
things inside it?

'Things' is not a useful concept..

There are three TV series in %HoH. Information for each TV series is
held in a corresponding hash reference. Between them, there are eight
roles in those three series. Each role has the name of the character
which is unique within series not necessarily unique across series
(nothing prevents you from adding an uncle john to all series or a role
friend with a name that differs across series or a character called anne
for a different role for each series).

Sinan

--
A. Sinan Unur <[email protected]>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
 
U

Uri Guttman

LS> I was being disingenuous -- I was able to figure out what there were 22
LS> of ... The part that is still a bogglement is why does OP consider a key
LS> and its associated value separate "things" , and - as you pointed out -
LS> what possible meaning could that number have? I did head over to google
LS> and search OP's posting history, and I think he's just antisocial and
LS> trollish.

sounds good to me. and scanning a tree is basic data structure coding
that is never a builtin in any lang i have heard of as it is way too
high level. let alone counting 'things' in the tree being a perl
builtin.

uri
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top