C
Christopher
I have a hash that is several levels deep.
ie:
'vars' => {
'$filers' => '10.10.10.10/32',
'$networksa' => '10.10.10.10/32',
'$networksb' => '10.50.0.0/16',
'$wintel_boxes' => '10.10.10.10/32',
},
'match' => {
'Rule' => {
'Doug' => {
'RuleSub' => {
'OUTBREAK' => {
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 =>
$networksa =>
$networksb =>
$wintel_boxes =>
match
Rule => HASH(0x17a918)
DOUG => HASH(0x17a924)
RuleSub => HASH(0x17a99c)
OUTBREAK => 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 =>
ie:
'vars' => {
'$filers' => '10.10.10.10/32',
'$networksa' => '10.10.10.10/32',
'$networksb' => '10.50.0.0/16',
'$wintel_boxes' => '10.10.10.10/32',
},
'match' => {
'Rule' => {
'Doug' => {
'RuleSub' => {
'OUTBREAK' => {
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 =>
$networksa =>
$networksb =>
$wintel_boxes =>
match
Rule => HASH(0x17a918)
DOUG => HASH(0x17a924)
RuleSub => HASH(0x17a99c)
OUTBREAK => 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 =>