in reply to More about module

  1. It depends on you needs. If there is a subroutine you are using in several scripts you should put it in a module.
  2. Probably. Loading a module will usually require a little more overhead than including all the code in your script.
  3. I may be missing something here, but I have never used, nor seen anyone else use, an include file in perl (one that wasn't a module, that is). I imagine you could do neat tricks with eval to include files in a script, though.
  4. Reusability. We are lazy and prefer to only type our code once, then use it whenever we like. Using the module system is the standard way of writing software components in perl and it provides (among other things) support for locating modules in shared (/usr/lib/perl) or private (~/my/perl) directories, namespace protection and version numbers for your modules.

Cheers,
--Moodster

Replies are listed 'Best First'.
Re: Re: More about module
by tachyon (Chancellor) on May 06, 2002 at 11:12 UTC

    3 I may be missing something here, but I have never used, nor seen anyone else use, an include file in perl (one that wasn't a module, that is). I imagine you could do neat tricks with eval to include files in a script, though.

    You are missing something:

    require "c:/some_script.pl"; print some_func_from_some_script();

    use Foo::Bar; is like BEGIN { require Foo::Bar } ie use is compile time, require is run time. You are just requiring in a file (the .pm is implicit as is the path which is assumed to be in @INC). See the docs.

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      Every day, you learn something new. :)

      But to be honest, I don't see why this should be better than putting your code in a proper module. It saves you the bother of messing around with Exporter, yes, but Exporter is your friend. Exporter wants to cuddle you and keep you safe from harm.

      Cheers,
      --Moodster

        Well, you could always define your subs in package main; :-)

        Joost -- ooh, i'm in an evil mood today :-)