Hi Daniwebbers,
can someone help me How to figure out the depth of a dynamic hash (hash of hashes) in perl. If it has consistent structure, we can traverse through while/foreach and find out the depth. Could anyone point me the right and best way to figure it out.
my %hash1 = (
name => {
first => "John",
last => "branham",
middle => "visa",
},
address => {
park => "cubbon",
doorno => "4/6",
other => {
division => "division",
city => "Cincinati",
state => "Ohio",
country => {
cont => "NA",
code => "USA",
pin => "51123",
},
district => "district",
}
},
status => "unmarried"
);
%hash2 might or might not have the structure.. for instance.. address might be blank.
Inshort am in need of a subroutine which could take an hash as an argument and return (highest) depth of the hash above example is 5 . $href->{"hash1"}->{"address"}->{other}->{country}->{code}.
I tried with recursive funtion. but with no success..
Any help would be highly appreciated.. Thanks