Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

How do I get my script to see my modules?

by Anonymous Monk
on Aug 24, 2000 at 23:50 UTC ( [id://29528]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to split my code up into libraries with a .lib extension. Using require works fine, but gives me a warning that all of the references to the said libraries' subs are not defined, although it still runs the subroutine. Is there any special syntax for calling these subs? Also, when I change the extension to .pm and use "use" with the directory where the libraries are added to @INC like so:
$INC[$#INC++] = "Directory";
This seems to work ok, except when the use function is stated, the @INC array seems to reset and forget that it has been appended. Any suggestions on either way of doing this?

Originally posted as a Categorized Question.

Replies are listed 'Best First'.
Re: How do I get my script to see my modules?
by Shendal (Hermit) on Aug 24, 2000 at 23:57 UTC
    You don't want to modify @INC directly (that can break autoloading and/or architecture specific directories may not get added properly). It's much safer to do it this way:
    use lib ('/path','/path/to/another/dir'); require 'foo.pl';
    Hope that helps,
    Shendal
Re: How do I get my script to see my modules?
by Anonymous Monk on Feb 01, 2001 at 22:59 UTC
    If your modules are installed in a subdirectory of the location of your script, you can try the following:
    use File::Basename; use lib dirname( $0 ); use MyModule;
    Dave
Re: How do I get my script to see my modules?
by Anonymous Monk on Jun 16, 2003 at 06:43 UTC
    Correct me if I'm wrong, but wouldn't this:

    $INC[$#INC++] = "Directory";
    Increment the $#INC value AFTER it accesses it?

    So in effect you're overwriting the last element, then incrementing the index value.

    Originally posted as a Categorized Answer.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://29528]
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: (3)
As of 2024-03-19 11:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found