It looks like you munged up the stuff in the code tags, so I'm not sure. However, it looks like you've used Data::Dumper to dump your data. If so, it appears like you might've done something like:
my %AG = ( 'BERF - Office of Director' => [ [ { SECTION => 'BERF' }, { GRADE => 'D1' }, { POSITION => 'DIRECTOR' }, { NAME => 'D. Fool' }, ] ] ); print Dumper(%AG);
So to access any element of your data structure, start at the top, and work your way down/in to your data element. So if you want to get the GRADE, you'd need to do something like this:
my $grade = $AG{'BERF - Office of Director'}[0][0]{GRADE};
If you look at the data, you can see the nested pair of square brackets: That means that you have an array inside of an array. I suspect that what you *really* wanted is more like this:
my %AG = ( 'BERF - Office of Director' => { SECTION=>'BERF', GRADE=>'D1', POSITION=>'DIRECTOR', NAME=>'D. +Fool' } );
This would make %AG a hash of hashes, and you could access GRADE like:
my $grade = $AG{'BERF - Office of Director'}{GRADE};
I'd suggest taking a short break from your current project and reading perldoc perldsc, perldoc perlreftut for a little while. Let me know if you need a bit more help.
Note: Oh, yeah, one other thing: If you're going to use Data::Dumper to print a data structure, be sure to pass a *reference* to the structure into the routine. So you'd use a statement like one of these:
my %hash = { a=>1, b=>2 }; my $ref = \%hash; # This will give you a nice dump of your hash print Dumper($ref); # This will give you the same kind of dump print Dumper(\%hash); # This will give you a *HORRIBLE* dump: print Dumper(%hash); # It'll give you something like: $VAR1 = 'a'; $VAR2 = 1; $VAR3 = 'b'; $VAR4 = 2;
...roboticus
When your only tool is a hammer, all problems look like your thumb.
In reply to Re^3: Counting Problem
by roboticus
in thread Counting Problem
by GuiPerl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |