Search code examples
linuxperlperl-module

How to check if the Perl Module is been installed in system or not


I have Perl Module (Net::Telnet) is been installed in location: /home/vinod/VK_Scripts/Practices/lib

I am executing below command to check if the module exists in system or not using below command -

perl -MNet::Telnet -e 'print "Installed\n"'
vinod@vinod-VirtualBox:~/VK_Scripts/Practices$ perl -MNet::Telnet -e 'print "Installed\n"'
Can't locate Net/Telnet.pm in @INC (you may need to install the Net::Telnet module) (@INC contains: /home/vinod/perl5/lib/perl5/5.30.0/x86_64-linux-gnu-thread-multi /home/vinod/perl5/lib/perl5/5.30.0 /home/vinod/perl5/lib/perl5/x86_64-linux-gnu-thread-multi /home/vinod/perl5/lib/perl5 /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).
BEGIN failed--compilation aborted.

So, I have added the lib path to PERL5LIB as suggested by @ikegami in this thread.

Command was -

export PERL5LIB=/home/vinod/perl5/lib/perl5:/home/vinod/VK_Scripts/Practices/lib

And now when I check with same command whether module exists in system or not by using below command it returns true.

vinod@vinod-VirtualBox:~/VK_Scripts/Practices$ perl -MNet::Telnet -e 'print "Installed\n"'
Installed

So, question here is is there any possibility I can check whether module is exists in possible location in perl -MNet::Telnet -e 'print "Installed\n"' command itself rather export them to PERL5LIB before.


Solution

  • You can specify the include path (one or multiple) for the Perl interpreter on the command line itself by the -I parameter:

    perl -I /home/vinod/VK_Scripts/Practices/lib -MNet::Telnet -e ''
    

    You can also inspect the exit code of your script. If it is installed it will be zero, otherwise you got something than zero.