I'm not very familiar with Perl, yet. I would like to construct a 2d array which will store data about pupils in our school. We have a number of pupils and for each pupil I want to store Name, ClassID, a variable number of CourseCodes.

In C++ I would create a class, because Name and ClassID would be strings and CourseCodes would be a dynamic array of some kind. Should I go OO in Perl, too, or is it possible to do something like:
@thePupils[23]->{"ClassID"} = "99-A";
This would store classID 99-A to the 23:rd pupil in the array.
@courses = @thePupils[23]->{"CourseCodes"};
This should store the 23:rd pupil's all course codes in an array for further processing.
I've tried these lines, but I get different errors. How should I declare the whole array?

jotti

In reply to 2d arrays in Perl? by jotti

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.