in reply to Re^2: How to allocate a struct?
in thread How to allocate a struct?

great to see some good posts on monks
can i also suggest u do a perldoc -f <builtin_command_name> when u dont want to bother with all the info and just u need a quick reminder.
try it out its fun
Do not wait to strike when the iron is hot! Make it hot by striking - WB Yeats

Replies are listed 'Best First'.
Re^4: How to allocate a struct?
by dissident (Beadle) on Oct 28, 2014 at 21:10 UTC

    I meanwhile read a lot of perldoc pages and in the perlmonks site. If it were not for the hassle to have to set up a .pm module for each different struct I'd like to use, I'd use the way described in perltoot. But what I want is just basic structs like in old C, without additional OOP features and the like I don't need for my project.

    I feel the lack of structs is really a problem, as there are countless implementations of struct simulations. Mouse, Moose, and all their forks. I really do not understand why the Perl gods don't add structs to Perl itself to make things easier and cleaner.

    So I finally decided to go the way Athanasius suggested in his update. This example of MooX really looks natural and straightforward, compared to the awkwardiness of the examples shown in the docs of the other packages like Moose and so on. But I ran to another problem, on which I probably better post a new question.

    Thanks again to all of you!

      I really do not understand why the Perl gods don't add structs to Perl itself to make things easier and cleaner.

      One good reason is that once you understand the facilities of Perl, for any given use-case where those coming from other languages might use a struct, there is nearly always a better, more perlish approach to solving the requirement.

      So, rather than ruing the lack of some facility that, even if someone started the process of adding that facility tomorrow, wouldn't be available for months if not years, why not describe your use-case in detail, and see if the monks can't offer you some alternative that is available now?


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        Thank you BrowserUk for your suggestion to describe the use-case/the project needs in more detail.

        What I want is a tree structure like a directory tree. I'd like to read the text files together with directory-specific configuration files into memory and collect all words marked to be used as search tags (and their aliases). In a second pass all documents are searched again and the tag index is completed. In the third and last pass the web site consisting of the files in the directory tree is built (merging the HTML design templates with the content text files producing html pages, and some generated pages like sitemaps, indexes, galleries and the like).

        This is the reason why I'd like to have structs where I can cleanly collect page data, image data, tags and so on.

        I could of course use the deprecated BASIC style without any technical problems. But I'd prefer not to use a global array for each and every struct member. Through appropriate naming the code would at least be relatively easy to understand and to modify. But dealing with lots of lists (arrays) of indices to global arrays would be cumbersome. Maybe there indeed exists a "Perl-ish" way to avoid this... but I am still a fresh novice and still need to learn the perlish way of thinking...