in reply to Re: execution log
in thread execution log

Thank you, mscudder! BTW...the expected use is simply for logging the execution of a working script, not for debugging, anyway. I had nearly given up on finding an event log, and will gladly use your package. Now...excuse the Perl-newbie dumb question - since this is a package, how do I use it in a script? Do I code a "use" statement, or perform an "exec" or "system"?

Replies are listed 'Best First'.
Re^3: execution log
by mscudder (Initiate) on May 09, 2006 at 18:24 UTC
    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.

      Wow - thank you SO much, mscudder! I'm working on a project to convert our DOS .bat scripts to Perl, while learning both script languages, and I spend a lot of time in the state of confusion. I appreciate your clear writing style, while still managing to avoid talking down to me.

        I hope it was of help.

        Thank you for your most kind complement.

        Best,
        Michael