JunhuiLi JunhuiLi - 1 month ago 7
Perl Question

failed to install my own perl module(pm file)

I have made my own perl modules(pm files),named test.pm

package test;
use Exporter;
use strict;
use File::Basename qw(basename dirname);
use Cwd qw(abs_path);
use File::Path qw(make_path);
use FindBin qw($Bin $Script);
BEGIN {
our @ISA = qw(Exporter);
our @EXPORT = qw(mkdirOrDie);
our $VERSION = 1.0;
}

sub mkdirOrDie
{
my ($dir) = @_ ;
if(!-d $dir){
make_path($dir);
$dir=abs_path($dir);
# timeLog("Directory Created: $dir");
}
}


and I tried to install this module as follows,

h2xs -AX -n test

perl Makefile.PL
make
make install


there is no error,and I copy the
test.pm
to
/usr/lib64/perl5/5.10.0/
,but when i call sub function using test, an error has occurred,

Undefined subroutine &main::mkdirOrDie called at /to/my/path/main.pl line 92


is there something i ignored?

Answer Source

It's unclear at which point things started to go wrong for you.

Firstly, test.pm is a bad name for a Perl module. Perl modules should have names that begin with upper case letters (and Test.pm is already taken).

You should run h2xs before writing your code - as it generates a module skeleton for you fill in. I hope it hasn't overwritten your code with an almost empty file! It's also worth noting that most people stopped using h2xs many years ago. These days we have tools like Module::Starter.

Then, running, make install (which you need to do with root permissions - so usually with sudo) is what installs your module into the system libraries. There should be no need to run that cp command afterwards.

As for why your code doesn't find the module, there are many possible reasons. Are you using Perl 5.10 or do you have other Perl versions installed? What does the code look like that you are trying to use? Does test.pm still include the code you think it does?

Need more information to be much help here.