I do not think of nested arrays in the same way as you do. You think encapsulation of arrays, whereas I thing 3 dimensional arrays. A cube for example, would serve you just fine. The first field would be the group, the second - the project, and the third (i'm guessing) the months.
Using a hash is a better idea, because it allows instant access to the data once you know the keys.
the code to parse through the following text
HASH
<xmp>
__DATA__
GROUP1 PROJECT1 DECEMBER DATA
GROUP2 PROJECT2 JANUARY DATA
GROUP1 PROJECT6 JULY DATA
GROUP4 PROJECT9 MAY DATA
GROUP5 PROJECT5 AUGUST NOW
__END DATA__
</xmp>
is as follows:
while ( <DATA> ) {
chomp( $_ ); #get rid of whitespace at end
@f = split( /\s/, $_ ); #split data up into an array
#ThreeDHash[ GROUP ][ PROJ ][ MONTH ] = DATA
$ThreeDHash{ $f[0] }{ $f[1] }{ $f[2] } = $f[ 4 ];
}
For Arrays, you can put things into a 3d Array as follows
#same as a hash, only with square brackets
# dont forget $index1/2/3 all have to be integers
# so you will have to index every entry to the file.
$ThreeDArray[ $index1 ][ $index2 ][ $index3 ] = $DATA;
Have Fun.
Regards,
XDB19
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.