Think about Loose Coupling | |
PerlMonks |
Re^2: Recursive Class:Struct syntax error?by markong (Pilgrim) |
on Dec 03, 2018 at 23:56 UTC ( [id://1226689]=note: print w/replies, xml ) | Need Help?? |
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 Section
Seekers of Perl Wisdom
|
|