As someone else mentioned, read perldoc perlmod. After that, read perldoc perlmodlib. You might also want to read Simple Module Tutorial, a tutorial written by our very own tachyon.

Basically though, you'll do something like this:

package LocalUtilities; require Exporter; our @ISA = qw( Exporter ); our @EXPORT_OK = qw( record_visit random_quote ); sub record_visit { # do stuff... } sub random_quote { # do other stuff... } 1; # Always end your modules with a true expression.
And then you'll use it like this:
use LocalUtilities qw( random_quote ); LocalUtilities::record_visit(); print random_quote();
You can do it without the Exporter stuff, but you might as well use it. Read perldoc Exporter for more information. You should probably also learn about h2xs as soon as possible so read perldoc h2xs too.

Since you have some C++ background, you will probably be interested in Perl's OO facilities. (You'll either love 'em or hate 'em.) You can find more information by reading the perlboot, perltoot, perltootc, perlobj, and perlbot perldocs and here in the Tutorials section.

Of course, someone may have already written code that could replace your utility functions; if so, it may even be more complete and better tested than your own. Check CPAN to find out. Finally, after you decide your module fills a niche not already filled by modules available on CPAN (or you think yours does it better), consider contributing your code. Read perlnewmod for some advice on how to do that.

-sauoq
"My two cents aren't worth a dime.";

In reply to Re: Better Style by sauoq
in thread Better Style by lunchbox

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.