I have a hash that is several levels deep.

ie:

'vars' => {
'$filers' => '10.10.10.10/32',
'$dmz_networks' => '10.10.10.10/32',
'$vpn_networks' => '10.50.0.0/16',
'$security_wintel_boxes' => '10.10.10.10/32',
},
'match' => {
'RuleResource' => {
'ITOC' => {
'RuleSubResource' => {
'VIRUS' => {


Basically a structure similar in nature to that, basically it could go
as deep as 8 keys deep with values potentially with each key, but
usually a value as some level.

I need to iterate over this and print it out in it's structure, but
with some formatting. DataDumper does a fine job of doing it in it's
way, but I cannot customize the pretty output, plus I need to utilize
the data in other ways.

So I figure I can load the "top level" keys (say there are 3 of them),
and then recurse over each subsequent key and gather and print as I
go.

Here is what I tried:

use Config::General;

my $match_file = qq(match.conf);

my $match_conf = new Config::General(
-file => $match_file,
-AutoTrue => 1);

my %match_config = $match_conf->getall;

$depth = 0;

foreach $key (keys %match_config) {
print "\t"x$depth;
print "\n$key\n";
$depth++;
&recurse_hash($match_config{$key},$depth);
}

sub recurse_hash {

$match = shift;
$depth = shift;

print "\t"x$depth;

foreach $key2 (keys %{$match}) {
print "$key2 => $match->{$key2}\n";
($match,$depth) = &recurse_hash($match->{$key2},$depth);
}
return ($match,$depth);
}

I get some results back, but I also get some funk, plus I don't get it
all, just portions..... I have racked my brain on this, and scoured
the groups for anykind of similar problem. Most are only 3 levels
deep, and the levels are known.

Here is the results:
Top level keys are typically gonna be (vars, match, and translate):
vars
$filers =>
$dmz_networks =>
$vpn_networks =>
$security_wintel_boxes =>
$filer_admin =>
$wireless_networks =>
$ras_networks =>
$my_networks =>
$vnc_networks =>

match
RuleResource => HASH(0x17a918)
ITOC => HASH(0x17a924)
RuleSubResource => HASH(0x17a99c)
VIRUS => HASH(0x17a9a8)
mail_body => blah blahblah
mail_cc =>
page_cc =>
interval =>
GUN =>
DOS =>
PN =>
srcnet =>

translate
CT2 => HASH(0x183a44)
27-74 => HASH(0x183abc)
msg_pattern => HASH(0x183b04)
".*filename: => (.*)" = "Bad file: \1"
27-75 =>
SN =>
MSG =>