Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Creating new perl modules.

by mulander (Monk)
on Oct 26, 2005 at 05:48 UTC ( [id://502952]=note: print w/replies, xml ) Need Help??


in reply to Creating new perl modules.

Add to your script:
use lib qw(/path/to/module);
use lib qw(); will tell the script in what directory it should search for your modules.
Another thing you may want to setup some variables so add this line just after use Exporter:
use vars qw(@ISA @EXPORTER);
Hope it helps.

Replies are listed 'Best First'.
Re^2: Creating new perl modules.
by radiantmatrix (Parson) on Oct 26, 2005 at 19:15 UTC

    And, it's worth mentioning a couple of things.

    If your module and the script that's using it are in the same directory, you don't need use lib. However, if you run it like this:

    C:\> perl C:\test\testbvt\hello.pl

    Perl sees C:\ as the current directory, and so can't find the modules. If you cd to C:\test\testbvt first, it should work. If this is the type of situation you have, you are wiser not to use lib, but to specify:

    C:\> perl -IC:\test\testbvt C:\test\testbvt\hello.pl

    The I option specifies a dir to add to @INC for that run only.

    On the other hand, if you have the following files:

    C:\test\hello.pl C:\test\Lib\Hello.pm

    You might want to change your package name to Lib::Hello instead of just Hello. Definitely read the docs for lib and perlmod, which cover how modules are located and how @INC works.

    Two quick last points. First, perl modules are not 'scripts': therefore you don't need (and probably shouldn't use) the #!/usr/bin/perl line in them. That line is a UNIX thing that lets the shell know to invoke the Perl interpreter for the file in question. By the time you import a module, the interpreter is working (not the shell).

    Second, make a habit of including use strict; use warnings; at the top of scripts and modules until you understand when they can/should be turned off. If you get warnings you don't understand, add use diagnostics; as well, which give a more verbose explanation.

    <-radiant.matrix->
    A collection of thoughts and links from the minds of geeks
    The Code that can be seen is not the true Code
    "In any sufficiently large group of people, most are idiots" - Kaa's Law
Re^2: Creating new perl modules.
by nisha (Sexton) on Oct 26, 2005 at 07:17 UTC
    Thank You very much!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2024-04-24 00:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found