Ask a Question related to PERL Beginners, Design and Development.
-
Christopher #1
Recurse over a hash without knowing any elements (except top level)
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 =>
Christopher Guest
-
CFDirectoy Recurse then collapse expand.
I want use CFDirectory to list the file and directories below it then with java script i want to to be able click on a directory and list all the... -
Error-flag references to non-existing hash elements?
I need a module that will support this behavior: use strict; my %hash = ('A' => 1, 'B' => 2); eval { my $x = $hash{C}; # reference to... -
New pure perl multi-level hash/array DBM
Hey all, I have just completed a very unique DBM, written in pure perl, and submitted it to CPAN. It has true multi-level hash/array support... -
[RCR] Dir.recurse
On Saturday, August 16, 2003, at 03:16 PM, Jim Bob wrote: You might check out find (in the standard distribution) and find2 (available through... -
Q- Empirical usable upper limit on hash array number of elements
carltonbrown@hotmail.com (Carlton Brown) wrote in message news:<aa611a32.0307090638.23f8297f@posting.google.com>... Hope it's not too much...



Reply With Quote

