Just my 2 eurocents:

1. I commonly use modules (so *.pm files) for anything that loads perl code (except sometimes configuration files created with Data::Dumper and the like)

2. Modules are probably a little slower (but i'd be surprised if it's significant).

3. If you load modules using the use MODULE statement, the file is loaded eval'ed at compile time, so syntax errors in the loaded files abort the script before running. Also, if you include an import routine in your module, it will be called whenever a use MODULE statement is found. (but the module itself will only be loaded and eval'ed once: when the first use is found.)

4. The main reason to declare functions and variables in different packages, is to make sure you don't override some other (global) vars or subroutines, and so you can create objects from them (object classes all need their own package name). In the end though, the *.pm extention is not really needed for all this, it just makes the whole process a little easier and less error-prone, because you can use *.pm files . (see 3.)

See also:

perldoc -f use perldoc -f require perldoc perlobj

Joost.


In reply to Re: More about module by Joost
in thread More about module by kwtow

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.