0

I have a perl scripts (proj_perl.pl , and proj_perl_client.pl) , I also created module proj_library.pm. My .pm looks:

package proj_library;
use base 'Exporter';
our @EXPORT = qw(help);


sub help{#my code}
1;

In my .pl scripts I invoke sub help and it looks:

#!/usr/bin/perl

use strict;
use warnings FATAL => 'all';
use feature 'say';
use IO::Socket;
use JSON;
use proj_library qw(help); #LOOK HERE!

Then I invoke help somewhere in the code. The problem is when I wan to run my script: ./pro_perl.pl Terminal shows me sth like this:

Can't locate proj_library.pm in @INC (you may need to install the proj_library module) (@INC 
contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.30.0 /usr/local/share/perl/5.30.0 
/usr/lib/x86_64-linux-gnu/perl5/5.30 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.30 
/usr/share/perl/5.30 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at 
./proj_perl.pl line 8.
BEGIN failed--compilation aborted at ./proj_perl.pl line 8.

So I don;t know what is going on!

Cyrus
  • 84,225
  • 14
  • 89
  • 153

2 Answers2

2

Add the following to tell Perl to search in the script's directory:

use FindBin qw( $RealBin );
use lib $RealBin;
ikegami
  • 367,544
  • 15
  • 269
  • 518
-1

Did you check that your pm is in your @INC? If you need to load a custom PM folder, check perldoc.perl.org/lib

use as:

use lib "."

or

use lib "my_libs/"
nnss
  • 50
  • 4
  • 1
    No, you shouldn't use either of those. You assume the current work directory is the script's directory, which is a really bad assumption – ikegami Oct 31 '20 at 15:26