Which data structures to use? (Hash.. etc.,)

T

Tom

Just started learning perl and i find it very interesting.
Well, I have to generate reports reading from a text file.

Following is the data-structure i have planned from which i can
extract relevant data for report.

Any suggestions on what data structures can be used here?
I understand hash tables.. however need some pointers to implement
effectively..

__________
Test Case 1. --------- Iter 0 --------->| |(Array)
| |----------|
|-- Iter 1 | |
| |----------|
|-- Iter 2 | |
| |----------|
|-- .. | |
| |----------|
|-- ..
| __________
|-- Iter n --------->| |(Array)
| | |
| |----------|
| | |
| |----------|
| | |
| |----------|
..
..
..
..
..
__________
Test Case n. --------- Iter 0 --------->| |(Array)
| |----------|
|-- Iter 1 | |
| |----------|
|-- Iter 2 | |
| |----------|
|-- .. | |
| |----------|
|-- ..
| __________
|-- Iter n --------->| |(Array)
| | |
| |----------|
| | |
| |----------|
| | |
| |----------|
 
B

Brian McCauley

Tom said:
Just started learning perl and i find it very interesting.
Well, I have to generate reports reading from a text file.

Following is the data-structure i have planned from which i can
extract relevant data for report.

Any suggestions on what data structures can be used here?
I understand hash tables.. however need some pointers to implement
effectively..

When we say "hash" in Perl we really mean "assocative array" - the fact
that Perl's builtin associative array type is implemented using hash
tables is largely irrelevant and it's only a historical accident that
the name emphasises this.

In Perl all more complex data structures are built out of arrays and
hashes (there's that word again) using pointers (or as we call then im
Perl references).

[ snip pictorial representation of the abstract concept array of array
of arrays ]

In Perl you'd implement that as an array of array of arrays. Well,
strictly an array of references to array of of references to arrays but
usually we take the "references to" as read.

Of course this presupposes that you'd correctly assesed in the first
place that your real-world problem is most naturally represented as an
array of array of arrays, and since you don't tell us anything about it
it's hard to judge.

The middle array in your model is described "iterations 0..n" and so I
can reasonably guess that array is the correct way to model that.

The outermost array you have described as "test case 1..n". If the test
cases are really just numbered not named then again an array is the
natural way to model that (although you should number from zero). If
the test cases are really named not numbered then a hash would be more
natural.

The innermost array in your model presumably holds data about a given
iteration of a given test. It is unlikely that the outcome of a single
iteration is a list of scalars and so it is unlikely that an array is
the natural way to store them. It is more likely that the outcome is a
vector. The distinction I'm drawing here is that the second element in
each vector always has a given meaning (e.g. average weight of rabit)
that is distinct from the 3rd element (e.g. total number of rabits).
Such vectors are, in Perl, naturally represented using hashes. Note you
are not really using hash here as a hash table but as a record with
named fields. Don't worry this is normal in Perl.
 
M

Michele Dondi

Following is the data-structure i have planned from which i can
extract relevant data for report.

Any suggestions on what data structures can be used here?
I understand hash tables.. however need some pointers to implement
effectively..
[snip data structures description]

Despite your very detailed description, it's not entirely clear to me
what you need. However I think you may be interested in e.g.:

perldoc perlref
perldoc perlreftut
perldoc perldsc
perldoc perllol


HTH,
Michele
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top