The simplest option -- if you don't care about reusability or maintainability -- is simply to paste the code into the file containing your script.

To create a (reusable) module, create a file in the format below, i.e. starting with the section labeled module interface, followed by the actual module code, and concluding with the numeral 1 (which should be the very last character in the file). Name the module file using the extension .pm, e.g., logmsg.pm.

Locate the .pm file in one of the module directories searched by the perl interpreter:

  1. Same directory as the script.
  2. One of the standard perl extension directories for your platform and perl distribution.
  3. Your own perl extension directory, in which case you'll have to add the library to the interpreter's search path using one of the perl -I command line option, @INC array, PERL5LIB environmental variable, lib pragma, or FindBin module.

To import the module into (make it accessible from within) your script, include the statement use Logmsg. The module name must be exactly as it appears in the corresponding package statement in the .pm file, including capitalization. By convention, at least the first letter of the module name should be upper case.

Good luck!

Best regards,
Michael

# ============================================== # # module interface # # ============================================== # package Logmsg; # for example -- name as you think best use strict; use Exporter(); our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); # set the version for version checking $VERSION = 1.0; @ISA = qw(Exporter); @EXPORT = qw( # autoexported symbols &logstart &logmsg &logstr &logstop &logstack ); %EXPORT_TAGS = (); # symbol groupings @EXPORT_OK = (); # symbols exported on request # ============================================== # # module code # # ============================================== # # ============================================== # # at end of file # # ============================================== # 1;

References

Programming with Perl Modules: Chapter 1, Sebastopol, CA:O'Reilly Media, Inc.

Perlmod - Perl Modules

Perlmodlib - Constructing New Perl Modules and Finding Existing Ones

Chapter 10, "Packages" in Wall, Larry, Tom Christiansen, and Jon Orwant, Programming Perl, Third Edition, Sebastopol, CA:O'Reilly Media, Inc., 2000, ISBN 0596000278.

Chapter 11, "Modules" in Programming Perl.

Chapter 12, "Packages, Libraries, and Modules," in Christiansen, Tom and Nathan Torkington, Perl Cookbook, Second Edition, Sebastopol, CA:O'Reilly Media, Inc., 2003, ISBN 0596003137.


In reply to Re^3: execution log by mscudder
in thread execution log by yburge

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.