Perl: How do I count hash sub keys?

Hi

I have a multidimensional hash slimier to bellow

How do I count hash sub keys?

Do I have to loop though the hash first?

my Actual data looks a bit like this
$HoH{$PolyNum}{$GroupNum}{$PointNum}={ Long=>$Long, Lat =>$Lat, Etc=>$ETC};

Open in new window


Due to data coruption I can't rely on PointNum I have to count them so I need to know how many points are in each GroupNum so I know if its a point (1), Line(2) , or Polygon(>2)  so I can process accordingly
I Know you can have more than 2 points on a line but this data does not

In the test bellow I get "Experimental keys on scalar is now forbidden at main.pl line 38."

use strict;
use warnings;

print "Hello World!\n";

my %hash = ( "barney" => "dinosaur", "elmo" => "monster");

# this works 
print  scalar keys %hash;
my %HoH;

$HoH{4}{ mash } = {
    captain  => "pierce",
    major    => "burns",
    corporal => "radar",
};

$HoH  {1} {flintstones} = {
        husband   => "fred",
        pal       => "barney",
    };
$HoH  {2} {jetsons}=  {
        husband   => "george",
        wife      => "jane",
        "his boy" => "elroy",  # Key quotes needed.
    };
$HoH  {3} {simpsons} = {
        husband   => "homer",
        wife      => "marge",
        kid       => "bart",
    };
  
  for my $num (sort keys %HoH){  
        for my $TV (sort keys %{$HoH{$num}} ){
print "\nNum keys $num " . scalar keys $HoH{$num}{$TV};
}

Open in new window

LVL 1
trevor1940Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

wilcoxonCommented:
The problem is that you are using keys on a hashref (eg scalar).  If you change line 35 to the below, it will work:
print "\nNum keys $num " . scalar keys %{$HoH{$num}{$TV}};

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
trevor1940Author Commented:
Thank you! I knew it was something simple
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.