You need a structure for the size table "N". I doubt that there is a CPAN module that can do this, because this is not a very common situation.
The problem is that the data structure is growing pretty fast, as well as complexity.
You can store an N-dimensional table in one list using a bit of math to convert an N-dimensional array into one dimension. Say that X represents the dimension of X, and X 'is the length of this dimension. For a two-dimensional table, you can get the value by doing the following:
X * Y` + Y.
For a three-dimensional table X, Y, Z, the answer will be:
X * (Y' * Z') + Y * Z' + Z
For a four-dimensional table W, X, Y, Z, the answer will be:
W * (X' * Y' * Z') + X * (Y' + Z') + Y * Z' + Z'
(I hope the math is correct).
Therefore, I can imagine such a structure for an N-dimensional table. It will include two different classes: one representing size information, and the other representing actual data (including all measurements).
- Size (Grade)
- Title (alphanumeric string)
- Measurement Size (Integer)
- N-table (class)
- Dimension Array (Dimension Class Objects)
- Array of data (alphanumeric strings)
You can get the number of measurements by looking at:
my $numOfDimensions = scalar @{$ntable->{DIMENSIONS}};
And you can get the dimension header $x
by looking at:
my xDimensionHeading = $ntable->{DIMENSION}->[$x]->{HEADING};
And the size of this measurement, looking at:
my xDimensionSize = $ntable->{DIMENSION}->[$x]->{SIZE};
Of course, you would do this with true object-oriented calls, not with empty links, but this gives you an idea of โโhow the structure will work.
Now you need a way to convert a list of integers that will represent the location of the cell in the cell in a one-dimensional array, and you will have the ability to receive and retrieve your data.
Will this be what you are looking for?
EDIT
Next to it, but I actually change the size of the table a lot (I canโt determine their size in advance), and if I realized that your solution is not suitable for this.
This adds a lot of complications ...
We need to throw out the size in the Dimension class. And we cannot use one dimensional array to store our data.
I hope you do not change the dimension of the table.
We could do something like this:
- N-table (class)
- Dimension Header List {DIMENSION} โ []
- List of data {DATA} โ [] (This may be a link to other lists)
The {DATA} list is a link of lists depending on the depth of the table. For instance:
my data_3D = $table_3D->{DATA}->[$x]->[$y]->[$z]; my data_2D = $table_2D->{DATA}->[$x]->[$y];
Number of dimensions scalar @{$table->{DIMENSION}}
.
The question is how can I access the data in such a way that dimensional neutral. I could require 2, 3, 4 or more dimensions, and I need to somehow structure my address in order to pull it out.
We may have some kind of cycling mechanism. We get a list of coordinates in @coordinates
, and then look at each coordinate. The latter will indicate the data. The rest will be just another reference to another array.
my $data = pop @coordinates;
It may also be possible to build a list of coordinates and then evaluate it. Again completely untested:
$coordinates = "[" . join ("]->[" => @coordinates . "]";
If there were three coordinates, that would be
$coordinates = "[$x]->[$y]->[$z]";
I'm not sure how a 1-dimensional array will work ...
From there, you can create an instruction and use eval
on it and get the data.
You must have several methods.
- Set dimensions
- Set cell
- Get cell
- Checking the table is complete (I have no idea how this will work.
This is more of a brain dump, but I think it might work. You do not have any given table parameters, and this can work for any N-dimensional table.