Hi, Monks ...

I recently asked for a review of my first module, and I received some very useful feedback. However, there is a question that I didn't ask that goes to the heart of my module's design, and perhaps future modules that I hope to write.

My module exports several functions; each function takes no arguments, and returns a scalar (or in one function, a three element array.) When I first started designing the module, my thought was to, instead of exporting the various functions, I would instead export a single hash, with the keys being the function names and the values being, obviously, the return of each function.

The reason I did not do that is because several of the functions may take several seconds to complete, and so the act of "use"ing the module in a script made the entire script take that longer amount of time to complete. (Note though, that if all of the functions are exported and used in the script, the script will take the same amount of time.)

Perhaps the answer to my question is "TMTOWTDI", but is there any kind of consensus to whether it is better to have a module export functions (even though the functions take no args) or variables?

thanks for all of the help I've gotten so far, and all of the help I'll be getting in the future! :-) -s-


In reply to should a module export FUNCTIONS or VARIABLES? by blueflashlight

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.