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


in reply to unknown number of dimensions of a multidimensional hash

If the hash is not ragged, you simply know its dimensionality. If you somehow lose this information

sub hashfirst { $_[0]->{($_) = keys %{$_[0]}} } sub shape { my $h = shift; my @s; for (;'HASH' ne ref $h; $h = hashfirst($h)) { push @s, scalar(keys %$h); } @s }

may help you remember. This feels like an X-Y question.