newbie01.perl has asked for the wisdom of the Perl Monks concerning the following question:

Hello to the Perl Highness ... :-)

Am not really sure whether I want modules or libraries. Am very confused so hopefully I can find the answers here.

I have several Perl scripts that are currently running as cron jobs. I want to be able to combine them as some sort of module or library or package instead that I can just call from another Perl script.

That is, for example, if I have a script script01 that remove old files and script script02 that monitors filesystem space. I want to be able to pout these two scripts into some sort of module or library that I can just invoke from another script that make require them. Is this possible or am I talking about senseless stuff here.

Your guidance will be very much appreciated

  • Comment on How to creater your own Perl modules/libraries?

Replies are listed 'Best First'.
Re: How to creater your own Perl modules/libraries?
by cdarke (Prior) on Nov 20, 2009 at 08:48 UTC
    module or library or package

    You are in danger of being bogged down by semantics. The term "library" does not really mean anything specific in perl. The terms package, namespace, and class can also mean the same thing. The term module is often used to be the same thing as well. That is a simplification, as you learn more Perl then you will find that those terms do actually have their own distinct meanings, but right now you can consider them to be more or less the same.

    So you want to create a module, read perlmod and perlmodlib. It is actually very easy. For example, put the following in MyModule.pm in the current directory:
    package MyModule; use warnings; use strict; # Insert your subroutines here # Don't forget this: 1;
    Then just use MyModule; and call the subroutines as (for example) MyModule::mysub();.

      This was an excellent post, but there's one caveat:

      # Don't forget this: 1;
      Note that this is not necessary. :-)

      UPDATE: If you don't already know that this is a joke, then please ignore it, or your module-writing life will be harder than it needs to be. If you don't want to ignore it, then at least read perlmod and the linked page carefully to see why it's a joke.

        Hi,

        Just want to confirm that the 1; is not necessary?

      Hi,

      Thanks for your response ... will try it out ...

Re: How to creater your own Perl modules/libraries?
by zentara (Cardinal) on Nov 20, 2009 at 13:34 UTC