Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: More about module

by moodster (Hermit)
on May 06, 2002 at 08:40 UTC ( [id://164250]=note: print w/replies, xml ) Need Help??


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 :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://164250]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2024-04-19 14:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found