GuiPerl:

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.