in reply to unknown number of dimensions of a multidimensional hash
Another thing you can do is use concatenated keys rather than a multidimensional data structure. (I don't know how critical the hierarchical nature is to your problem solution) That is, instead of:
you would use$data {$a}{$b} $data {$a}{$b}{$c} $data {$d}{$e}
Then to access the keys you'd use your standard keys operator:$data{join "\0", $a, $b} $data{join "\0", $a, $b, $c} $data{join "\0", $d, $e}
The main caveat is that your "key separator" should be something that doesn't appear in your keys. I chose "\0" in this example assuming that your keys aren't likely to contain NUL bytes.for (keys %data) { # you could do something with $data{$_} directly, # or if you need access to the individual keys ... my @keys = split /\0/; # ... }
|
|---|