How to load Perl modules using non-standard directories?
I download the trace module from cpan website and put into non-standard directories(/home/nrama/perl-script). but It doesn't taking my non-standard directories while executing below script. please let me know how to resolve this issue.
Trace module URL:
https://metacpan.org/pod/release/JV/Debug-Trace-0.05/lib/Debug/Trace.pm
Error:
syntax error at shift.pl line 3, near "use Trace." Execution of shift.pl aborted due to compilation errors.
Sample script:-
use strict;
use lib ("/home/nrama/perl-script");
use Trace.pm;
func('Nataraj', 'vino', 'mano' );
sub func {
my $name_1 = shift;
my $name_2 = shift;
my $name_3 = shift;
print "say hello to $name_1 $name_2 $name_3\n";
}
Note: Using perl, v5.6.0
use Trace.pm;
is not valid Perl, thus the syntax error. That should be
use Debug::Trace;
Furthermore, it makes no sense to harcode an absolute path in a script. You should remove
use lib ("/home/nrama/perl-script");
and either set env var PERL5LIB
to that path in the login script
export PERL5LIB="$HOME/perl-script"
or replace it with a relative path to the script such as
use FindBin qw( $RealBin );
use lib $RealBin;
or
use FindBin qw( $RealBin );
use lib "$RealBin/lib";