One way to handle this would be to put your data into a database and query it out. That can be useful especially if you have many many records or you have a data set that grows over time, and you don't want to build it repeatedly.
I'd probably represent your data with an array of hashes.
my @records = (
{ employee => 10001, form => 10, date => 20090101, },
{ employee => 10002, form => 10, date => 20080515, },
{ employee => 10003, form => 10, date => 20080323, },
);
What's nice about this is that each hash can expand to have more fields as necessary. When you want to summarize by any given field, you can do this:
sub summarize_by {
my $field_name = shift @_;
my %out;
for my $r ( @records ) {
push @{ $out{$r->{$field_name}} }, $r;
}
return \%out;
}
What you'd get from that is a hash of arrays of hashes. Each key of the top level hash is a unique value of the field you specified, and that hash's values are references to an array of records that had that key-value combination.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.