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:
$data {$a}{$b}
$data {$a}{$b}{$c}
$data {$d}{$e}
you would use
$data{join "\0", $a, $b}
$data{join "\0", $a, $b, $c}
$data{join "\0", $d, $e}
Then to access the keys you'd use your standard keys operator:
for (keys %data) {
# you could do something with $data{$_} directly,
# or if you need access to the individual keys ...
my @keys = split /\0/;
# ...
}
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.
|