List,
First I would like to thank all who provided input.. With the help of the
this list, I was able to figure out what I needed to change to get it all
working.. And we have successfully kept VB out (Yippy!)..
Now to the solution (note: I have copied the little test code and its output
below.. Please pardon the misspelt words in the scalar text..)..
Both hashes (%Instance and %PlcyActions) need to be defined as a reference..
So %Instance should have been defined in the Top level structure as:
INSTNCE => \%Instance
This assigns a reference to the hash to the key INSTNCE.. The hash in the
second level structure was redefined in the same way.. This makes perfect
sense, and once I saw that, I knew how to get to the data on all levels..
Now to access it, one additional change was needed.. To access the scalar in
the top level I use:
$Policy->{INSTNCE}{$CondID}->{DESCRPT}
To go all the way to the bottom, I use:
$Policy->{INSTNCE}{$CondID}->{ACTIONS}{START}{SEVRTY}
Again, one the answer was discovered, it all made perfect sense..
Rob, the keys are set to the same values for the test.. I will try the data
dumper.. As I start filling out the structure.. The test code posted is just
the tip of the iceberg so to speak.. The real structure is a lot more
complicated.. This whole piece is actually just a subset of the entire
structure..
Flk k
P.S. My back ground.. Been programming going back to assembler in the 70's..
I always use the "use strict" declarative, and run perl with the "-w"
command line switch.. I do unless I am dealing with code someone else wrote,
and I have'nt had the chance to clean it up (I've redone scores at my
current employer)..
Also I grew up in the days before the internet.. As such I tend to RTFM
(Read The 'Friendly" Manual) long before I go to any list.. I have more
books on perl than you can imagine (as well as C, Python, etc., etc.).. And
then only post after hours of reading FAQ's and posts.. As I said in my
post..
Code follows:
#!perl -w
use strict;
my %Instance;
my %PlcyActions;
my $Policy;
my $PlcyName = "My Most Exelent Good Policy";
my $PlcyDesc = "A good descrition for a policy";
my $Interval = "10h:20m:15s";
my $SourceShortName = "Coda";
my ($CondID, $InstDesc, $Object, $Threshold, $NewOne);
my ($Severity, $MsgText, $AutoAct);
$Policy = {
NAME => $PlcyName,
DESCRPT => $PlcyDesc,
INTERVL => $Interval,
CODA => $SourceShortName,
INSTNCE => \%Instance,
};
$InstDesc = "BadIncident";
$CondID = "12345678";
$CondID = "CONDID_".$CondID;
$Object = "To get this thing to print";
$Threshold = "How much pain can I take";
%Instance = (
$CondID => {
DESCRPT => $InstDesc,
OBJECT => $Object,
THRESHD => $Threshold,
ACTIONS => \%PlcyActions,
},
);
$Severity = "SupperDupperHigh";
$MsgText = "Head for the hills";
$AutoAct = "Shut her down";
%PlcyActions = (
START => {
SEVRTY => $Severity,
TEXT => $MsgText,
AUTACTS => $AutoAct,
},
CONT => {
SEVRTY => $Severity,
TEXT => $MsgText,
AUTACTS => $AutoAct,
},
END => {
SEVRTY => $Severity,
TEXT => $MsgText,
AUTACTS => $AutoAct,
},
);
print "\n-------------------------------------------------\n";
print "Top level access..\n";
print "\t\$Policy->{NAME}:\n\t\t\"$Policy->{NAME}\"..\n";
print "\t\$Policy->{DESCRPT}:\n\t\t\"$Policy->{DESCRPT}\"..\n";
print "\t\$Policy->{INTERVL}:\n\t\t\"$Policy->{INTERVL}\"..\n";
print "\t\$Policy->{CODA}:\n\t\t\"$Policy->{CODA}\"..\n";
print "-------------------------------------------------\n";
print "-------------------------------------------------\n";
print "Second level access..\n";
print "\n\t\$Policy->{INSTNCE}:".
"\n\t\t\"$Policy->{INSTNCE}\"..\n";
print "\n\t\$Policy->{INSTNCE}{\$CondID}:".
"\n\t\t\"$Policy->{INSTNCE}{$CondID}\"..\n";
print "\n\t\$Policy->{INSTNCE}{\$CondID}->{THRESHD}:".
"\n\t\t\"$Policy->{INSTNCE}{$CondID}->{THRESHD}\"..\n";
print "-------------------------------------------------\n";
print "-------------------------------------------------\n";
print "All the way..\n";
print "\n\t\$Policy->{INSTNCE}:".
"\n\t\t\"$Policy->{INSTNCE}\"..\n";
print "\n\t\$Policy->{INSTNCE}{\$CondID}->{ACTIONS}:".
"\n\t\t\"$Policy->{INSTNCE}{$CondID}->{ACTIONS}\"..\n";
print "\n\t\$Policy->{INSTNCE}{\$CondID}->{ACTIONS}{START}{SEVRTY}:".
"\n\t\t\"$Policy->{INSTNCE}{$CondID}->{ACTIONS}{START}{SEVRTY}\"..\n";
print "\n\t\$Policy->{INSTNCE}{\$CondID}->{ACTIONS}{CONT}{TEXT}:".
"\n\t\t\"$Policy->{INSTNCE}{$CondID}->{ACTIONS}{CONT}{TEXT}\"..\n";
print "\n\t\$Policy->{INSTNCE}{\$CondID}->{ACTIONS}{END}{AUTACTS}:".
"\n\t\t\"$Policy->{INSTNCE}{$CondID}->{ACTIONS}{END}{AUTACTS}\"..\n";
print "-------------------------------------------------\n";
Program output:
======================================================================
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\eendh66\Desktop>"test hashs.pl"
-------------------------------------------------
Top level access..
$Policy->{NAME}:
"My Most Exelent Good Policy"..
$Policy->{DESCRPT}:
"A good descrition for a policy"..
$Policy->{INTERVL}:
"10h:20m:15s"..
$Policy->{CODA}:
"Coda"..
-------------------------------------------------
-------------------------------------------------
Second level access..
$Policy->{INSTNCE}:
"HASH(0x182f948)"..
$Policy->{INSTNCE}{$CondID}:
"HASH(0x184af40)"..
$Policy->{INSTNCE}{$CondID}->{THRESHD}:
"How much pain can I take"..
-------------------------------------------------
-------------------------------------------------
All the way..
$Policy->{INSTNCE}:
"HASH(0x182f948)"..
$Policy->{INSTNCE}{$CondID}->{ACTIONS}:
"HASH(0x182f960)"..
$Policy->{INSTNCE}{$CondID}->{ACTIONS}{START}{SEVRTY}:
"SupperDupperHigh"..
$Policy->{INSTNCE}{$CondID}->{ACTIONS}{CONT}{TEXT}:
"Head for the hills"..
$Policy->{INSTNCE}{$CondID}->{ACTIONS}{END}{AUTACTS}:
"Shut her down"..
-------------------------------------------------
C:\Documents and Settings\eendh66\Desktop>
======================================================================
Flk k
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/