On Wed, Sep 28, 2011 at 10:33 AM, Frank Kleinburg <fklei...@gmail.com> wrote: > $Policy = { > NAME => $PlcyName, > DESCRPT => $PlcyDesc, > INSTNCE => { %Instance }, > }; > > %Instance = ( > $CondID => { > DESCRPT => $InstDesc, > ACTIONS => {%PlcyActions}, > }, > ); > > %PlcyActions = ( > START => { > SEVRTY => $Severity, > TEXT => $MsgText, > AUTACTS => $AutoAct, > }, > CONT => { > SEVRTY => $Severity, > TEXT => $MsgText, > AUTACTS => $AutoAct, > }, > END => { > SEVRTY => $Severity, > TEXT => $MsgText, > AUTACTS => $AutoAct, > }, > );
You should always use the 'strict' and 'warnings' pragmas. These will help you catch subtle errors in your code. They basically force you to declare your variables and that sort of thing (e.g., use 'my' to declare lexically-scoped variables). use strict; use warnings; You appear to have left some parts out of this example, and you also appear to be assigning these structures in reverse order (e.g., $Policy->{INSTNCE} is supposed to contain a new hash reference to a copy of %Instance, which is declared later). Pay particular attention to the /new/ and /copy/ bits there. The {} syntax creates a new anonymous hash reference, which you then copy the contents of %Instance into (or would, if things were ordered properly). $Policy->{INSTNCE} and $Instance would be two different data structures that happen to look the same initially. You might prefer to make them refer to the same thing, in which case you'd need to use \ to reference the existing hash. See `perldoc perlref'. For example: my %Instance = ( # ... ); my $Policy = { NAME => $PlcyName, DESCRPT => $PlcyDesc, INSTNCE => \%Instance }; > If want to access the value stored in $InstDesc, I can through > $Instance{$CondID}{DESCRPT}.. However I can't access the $InstDesc scalar > from the top.. If I try to print the obvious (at least to me): > > $Policy->{INSTNCE}{$CondID}{DESCRPT} > > I get the "use of an uninitialized in concatenation" warning.. If I try to > print the following: > > $Policy->{INSTNCE}->$Instance{$CondID}{DESCRPT} > > I'd get: > > HASH(0x235f34)->BadIncident > (Note: "BadIncident" is current value of $InstDesc) I don't see any concatenation happening so unless it's implicit I wonder if maybe you're leaving out some significant code. Are you certain that $CondID is defined and has a sensible value? You can use Data::Dumper to analyze the data structures and data that you /actually/ have and compare that to what you /think/ you have. use Data::Dumper; print STDERR "CondID=$CondID\n"; print STDERR Dumper $Policy; > Can someone explain how to access $InstDesc?? Also please explain how I > would access (that is read from or write to) to the $Severity scalar on the > bottom structure.. You _seem_ to already grasp the syntax required to dereference a hash reference and access a hash element so I don't think that your problem is this. I would recommend you experiment with Data::Dumper to figure out what the data structure actually is and see if that helps. You might also benefit from writing out other variables used (e.g., for keys). As a side note, your hash key names are pretty arbitrarily shortened and I find it rather difficult to read and use them. Some of them are only missing a single letter and often are side-by-side with longer key names. I would suggest you refactor the code to use fully descriptive words instead of those shortened names (unless there's a technical reason why you aren't). > p.s. I need to get this working or the boss has threatened to have it > written in vb script.. Please help.. Dear <insert_deity_here>...! :'( -- Brandon McCaig <http://www.bamccaig.com/> <bamcc...@gmail.com> V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl. Castopulence Software <http://www.castopulence.org/> <bamcc...@castopulence.org> -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/