It sounds like Struct doesn't easily support this kind of initialization.

Put simply, in OO parlance, a Struct is a class without methods. Thus you can only define members ("attributes"). To work with structs, as with objects you need to create them, and (maybe contestually) initialize its members.

Your original code was defining a struct *and* trying to initilize its members, which is not supposed to work: using a class you would use a constructor for that task.

Clearly, this can be done by writing a hash-of-hashes-of-hashes as others have suggested, and I eventually used.

Mind that HoH it's not the "perfect" data structure for the job: as bliako has already noted you won't get elements back in any predictable order without counting that now its up to you to walk back and forth the nested maze of elements and this will get surprisingly complex if you need to address the general case: take a look at Data::Walk.

This was obviously not a perfect situation in which to use Struct. :-)

Because you were using the struct as a sort of "root hash element" which does not make much sense: if you do want to learn it, why not use a Tree-Simple whose nodes are Structs?

I bet that, if you are interested in programming, won't be that easy to avoid trees ;).


In reply to Re^2: Recursive Class:Struct syntax error? by markong
in thread Recursive Class:Struct syntax error? by ibm1620

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.