in reply to How many levels of indirection in a Hash?

Absolutely! Thanks for putting it that way. How do you find out how deep it goes? ... without cheating when you create the hash :)
use warnings; use strict; my %hash; $hash{three}{levels}{deep} = 7500; $hash{process}{three}{levels}{deep} = 9000; $hash{process}{numberoflevels} = 4; for my $process(qw/ process no_process /){ my $hashbase; if (exists $hash{$process}){ $hashbase = $hash{$process}; } else { $hashbase = \%hash; } print "$process - ",$hashbase->{three}{levels}{deep},"\n"; }

Replies are listed 'Best First'.
Re^2: How many levels of indirection in a Hash?
by Roy Johnson (Monsignor) on Jun 07, 2005 at 23:39 UTC
    A HoH can go to varying depths. Do you want to traverse the whole HoH to find the deepest element, or do you know the chain you want to go down? The basic strategy is: if a value is a ref (ref $href->{$key} eq 'HASH') then descend a level ($href = $href->{$key}), increment your depth counter, and look again. The only tricky part is determining which keys you look at.

    Caution: Contents may have been coded under pressure.