Robticus,

The data structure that I want is in fact the one you had mentioned (i.e. A Hash of Hashes). My code has been generating this kind of structure.

#Foreach that loops through @rows which stores data from a CSV file. foreach my $rec (@rows) { foreach my $dept (@Divisions) { if ($rec->[5] =~ /^$dept/ && $rec->[8] =~ /^P\W[1-5]|D\W[1 +-2]|AD\w|DD\w|DG/) { my $Rec = { GRADE=>strip_hyphen($rec->[0]), POSITION=>$rec->[1], NAME=>invert_name($rec->[2]) + }; #The Divison is then added here push @{$AG{$rec->[4]}},$Rec; } } } <code> Dump of the %AG structure generated by logic above: VAR1 = 'ESRD - Office of Director'; $VAR2 = [ { 'NAME' => 'A. Smith', 'POSITION' => 'DIRECTOR', 'GRADE' => 'D1' }, { 'NAME' => 'P. Green', 'POSITION' => 'SENIOR DIRECTOR', 'GRADE' => 'D2' } ]; $VAR3 = 'BERF - Office of Technology'; $VAR4 = [ { 'NAME' => 'G. Tekola', 'POSITION' => 'JUNIOR OFFICER', 'GRADE' => 'P1' }, { 'NAME' => 'P. Brown', 'POSITION' => 'JUNIOR OFFICER', 'GRADE' => 'P1' }, { 'NAME' => 'T. Green', 'POSITION' => 'Technology Officer', 'GRADE' => 'P2' }, { 'NAME' => 'T. Green', 'POSITION' => 'Technology Officer', 'GRADE' => 'P2' }, { 'NAME' => 'T. Green', 'POSITION' => 'Technology Chief', 'GRADE' => 'P3' }, ];
I then can access the data using the following logic:
foreach my $A (sort keys %AG) { foreach my $p ( sort { substr($$a{GRADE},0,1) cmp substr($$b{GR +ADE},0,1) || substr($$b{GRADE},0,2) cmp substr($$a{GRADE},0,2)} @{$AA +{$A}}) { my( $grade_nums,$grade, $name,$position ) = ($p->{GRADE_NUMS},$p->{'G +RADE'}, $p->{'NAME'},$p->{'POSITION'} ); print $grade_nums,$grade, $name,$position,"\n"; } }
How do I then implement you counter logic in this type of structure? A small pointer would be appreciated. I did read Perldesc which helped me to develop my data structure. Maybe I need to change it? And yes, I will try to invest in a good editor. Maybe Komodo.

In reply to Re^4: Counting Problem by Anonymous Monk
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.