tags:

views:

240

answers:

4

Assume I downloaded Date::Calc from http://guest.engelschall.com/~sb/download/.

Now, I have a script, xxx.pl, which resides in the same directory as the untar-ed "thing" that I downloaded from the link above When untar-ed, it creates a "Date-Calc-5.6" folder with tons of stuff.

How do I include Date::Calc in xxx.pl? (I keep getting "Can't locate Date/Calc.pm in @INC" errors)

+2  A: 

You have to install the module. In most cases, this is best achieved by ignoring the source code tarball and using the cpan utility (on *nix) or the PPM manager (on ActivePerl for Windows).

David Dorward
http://strawberryperl.com/ is another (*and in my opinion superior*) perl for windows. It includes cpan with all that it needs (*make and a compiler*)
Nifle
You can install from the current directory with `cpan .`
brian d foy
+7  A: 

You first need to install the module.

In your @INC statement, specify the directory containing your Perl modules. Or use the statement: use lib "path" to be able to load modules via additional use statements.

Alex Reynolds
+1  A: 

Installing is the preferred method, but if you just want to try it without installing you can do this.

use strict;
use warnings;
use lib '/home/jeremy/Desktop/Date-Calc-5.8/lib';
use Date::Calc;

Please switch out my directory with where yours is unzipped. Also please read about lib.

J.J.
+1  A: 

You don't necessarily need to build and install the module. If the module is pure Perl and the build process doesn't create any new code files, you may be able to use a module while it's "still in the box". Assuming that's the case, there's more than one way to do it.

EDIT: It doesn't look like Date::Calc is pure Perl. You will probably at least have to build it before you can use the module.

  1. Set the $PERL5LIB environment variable to include the package distribution directory.

  2. Invoke perl with the -I switch

    perl -I/the/distribution/dir myscript.pl

  3. Put the -I switch on the #! (first) line of the script

    #!/usr/bin/perl -I/the/distribution/dir

  4. Use use lib in the script

    use lib qw(/the/distribution/dir);

    use The::Package;

  5. Put the distribution directory into the @INC variable

    push @INC, "/the/distribution/dir";

    require The::Package;

or

BEGIN {
    push @INC, "/the/distribution/dir";
}
use The::Package;
mobrule