[comp.lang.perl] Including home-rolled libraries

jas@ISI.EDU (Jeff Sullivan) (02/28/91)

I have gotten a new random number library together which reimp,ementes
the srand and rand functions according to Knuth (Thanks, Bill!).

Anyway, I wanted to create a directory for the libraries I'm
collecting, so I created a library called ~/.perlLib

where I symbolically link to all of the perl libraries I've FTP'd or
created.

The problem is, when I say;

require "~/.perlLib/random.pl";

I get the error:

Can't locate ~/.perlLib/random.pl in @INC at roll line 3.

So, I tried this at the top of my program:

#!/usr/bin/perl -I~/.perlLib

to add ~/.perlLib to the @INC array, and it's there when I look, but
the same error occurs.

What am I doing wrong?

jas

--
--------------------------------------------------------------------------
Jeffrey A. Sullivan		| Senior Systems Programmer
jas@venera.isi.edu		| Information Sciences Institute
jas@isi.edu                    	| University of Southern California

piet@cs.ruu.nl (Piet van Oostrum) (02/28/91)

>>>>> jas@ISI.EDU (Jeff Sullivan) (JS) writes:

JS> The problem is, when I say;

JS> require "~/.perlLib/random.pl";

JS> I get the error:

JS> Can't locate ~/.perlLib/random.pl in @INC at roll line 3.

The problem is that ~/... is not a proper filename (unless in your current
directory you have a directory named '~'.

The expansion of ~ to your home directory is a function of the shell (and
not all shells do this).

So try to let the shell do the expansion:

require <~/.perlLib/random.pl>;
-- 
Piet* van Oostrum, Dept of Computer Science, Utrecht University,
Padualaan 14, P.O. Box 80.089, 3508 TB Utrecht, The Netherlands.
Telephone: +31 30 531806   Uucp:   uunet!mcsun!ruuinf!piet
Telefax:   +31 30 513791   Internet:  piet@cs.ruu.nl   (*`Pete')

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (03/02/91)

In article <1991Feb28.130152.25669@cs.ruu.nl> piet@cs.ruu.nl (Piet van Oostrum) writes:
: So try to let the shell do the expansion:
: 
: require <~/.perlLib/random.pl>;

That's cute, but a lot less efficient (currently) than saying

  require "$ENV{'HOME'}/.perlLib/random.pl";

or, more to the point,

  unshift(@INC, "$ENV{'HOME'}/.perlLib");
  require "random.pl";

Larry