Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Including files

by chacham (Priest)
on Dec 07, 2011 at 16:54 UTC ( #942285=note: print w/ replies, xml ) Need Help??


in reply to Including files

> use lib 'path/to/the/modules';

and for same directory files (as i just figured out), no path is needed, just the name. For example, including my local db module:"

use lib 'db';


Comment on Re: Including files
Re^2: Including files
by Juerd (Abbot) on Dec 09, 2011 at 11:46 UTC

    If the module you're including is actually in the current directory, no use lib is required at all, since the current working directory, also known as ".", is already in @INC by default.

      Let me get this straight:
      • ~/abc/moo.pl
      • ~/abc/cow.pm
      • ~/zyx/cow.pm
      • current directory is ~/zyx

      moo.pl has:

      • use cow
      • use lib 'cow'

      When i execute moo.pl, . is set to ~/zyx, so:

      • use cow means ~/zyx/cow.pm
      • use lib 'cow' means ~/abc/cow.pm

      Did i get it right that, basically, there is a difference between the "current" directory and the directory of the pl file. Or, put another way, if i keep all my project files in the same directory, like we do during development, and the directory may change, and the directory i execute it from may change, "use lib" will work "as expected".

        Did i get it right that

        No. Read lib. use lib 'cow'; is the standard, clean alternative to unshift @INC, 'cow'; It adds a directory to the search locations; it does not identify or pull in any files into the current program.

        if i keep all my project files in the same directory, ... "use lib" will work "as expected".

        No; if you do that, then you never need use lib ... at all, for the simple reason that '.' is in @INC by default.

        I reckon we are the only monastery ever to have a dungeon stuffed with 16,000 zombies.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2014-12-26 04:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (165 votes), past polls