Perl, Can't locate Packet/UDP/Syslog.pm in #INC | custom modules - perl

Anybody please can spot a mistake here? I do have one perl script and 3 custom perl modules. I specified location of the modules using export, also using -I, also inside the script using:
use lib '/var/pwn/syslog-generator/perl-modules/';
but script still fails with common error:
Can't locate Packet/UDP/Syslog.pm in #INC (#INC contains: /var/pwn/syslog-generator/perl-modules/ ./ /etc/perl /usr/local/lib/perl/5.14.2 /usr/local/share/perl/5.14.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.14 /usr/share/perl/5.14 /usr/local/lib/site_perl .) at raw-syslog.pl line 5.
BEGIN failed--compilation aborted at raw-syslog.pl line 5.
modules are located here:
ls /var/pwn/syslog-generator/perl-modules
Packet.pm Syslog.pm UDP.pm
perl -V
Compiled at Sep 30 2013 03:45:34
%ENV:
PERL5LIB=":/var/pwn/syslog-generator/perl-modules/"
#INC:
/var/pwn/syslog-generator/perl-modules/
/etc/perl
/usr/local/lib/perl/5.14.2
/usr/local/share/perl/5.14.2
/usr/lib/perl5
/usr/share/perl5
/usr/lib/perl/5.14
/usr/share/perl/5.14
/usr/local/lib/site_perl
And my perl script starts like this:
#!/usr/bin/perl
use strict; use warnings;
use lib './';
use lib '/var/pwn/syslog-generator/perl-modules/';
use Packet::UDP::Syslog;
use POSIX qw/strftime/;
I also tryed to start the script with -Idirectory [specify #INC/#include directory], but:
perl -I /var/pwn/syslog-generator/perl-modules raw-syslog.pl
Can't locate Packet/UDP/Syslog.pm in #INC (#INC contains: /var/pwn/syslog-generator/perl-modules/ ./ /var/pwn/syslog-generator/perl-modules /etc/perl /usr/local/lib/perl/5.14.2 /usr/local/share/perl/5.14.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.14 /usr/share/perl/5.14 /usr/local/lib/site_perl .) at raw-syslog.pl line 5.
BEGIN failed--compilation aborted at raw-syslog.pl line 5.
again, no luck. Something obvious I am missing?
Thank you

Do you have 3 modules in 3 files called Packet.pm, Syslog.pm, and UDP.pm?
Do they have package Packet; , package Syslog; and package UDP; respectively at their top?
If so, you need to load each one of them separately using
use Packet;
use Syslog;
use UDP;
On the other hand, if you have one file in Packet/Syslog/UDP.pm then it has to have
package Packet::Syslog::UDP; at the top and you'd load it using
use Packet::Syslog::UDP;
Oh, and BTW, if this is up to you, I'd strongly recommend using a company or project specific module name-space. So instead of 'Packet.pm' I'd create a file called 'Company/Packet.pm' which would have package Company::Packet; at the top and I'd load it with use Company::Packet; Otherwise you'll easily bump into modules with the same name.
Some articles that might shed more light on the subject:
How to create a Perl Module for code reuse?
Packages, modules, distributions, and namespaces in Perl
(disclaimer: articles written by myself)

When you use Packet::UDP::Syslog, Perl will mangle that name to the path Packet/UDP/Syslog.pm. It will then loop through the #INC directories and look for matches:
/var/pwn/syslog-generator/perl-modules/Packet/UDP/Syslog.pm
/etc/perl/Packet/UDP/Syslog.pm
/usr/local/lib/perl/5.14.2/Packet/UDP/Syslog.pm
/usr/local/share/perl/5.14.2/Packet/UDP/Syslog.pm
/usr/lib/perl5/Packet/UDP/Syslog.pm
/usr/share/perl5/Packet/UDP/Syslog.pm
/usr/lib/perl/5.14/Packet/UDP/Syslog.pm
/usr/share/perl/5.14/Packet/UDP/Syslog.pm
/usr/local/lib/site_perl/Packet/UDP/Syslog.pm
./Packet/UDP/Syslog.pm
If none of those files exists, the module hasn't been found. However, you only have these files:
/var/pwn/syslog-generator/perl-modules/Packet.pm
/var/pwn/syslog-generator/perl-modules/Syslog.pm
/var/pwn/syslog-generator/perl-modules/UDP.pm
That's not correct because the file system hierarchy is relevant when resolving namespaces. I suggest you properly install your module rather than copying files into a directory. You can use cpan or cpanm to install the module, and can use local::lib to install to a custom module location.

Related

Perl throws "Can't locate Config/YAML.pm in #INC"

I'm getting Can't locate Config/YAML.pm in #INC (you may need to install the Config::YAML module) while running a perl script.
Can't locate Config/YAML.pm in #INC (you may need to install the
Config::YAML module) (#INC contains: /etc/perl
/usr/local/lib/perl/5.18.2 /usr/local/share/perl/5.18.2 /usr/lib/perl5
/usr/share/perl5 /usr/lib/perl/5.18 /usr/share/perl/5.18
/usr/local/lib/site_perl .) at myperlscript line 8. BEGIN
failed--compilation aborted at myperlscript line 8.
Line 8 of the script shows use Config::YAML;.
I'm using Ubuntu and have installed the libdata-yaml-perl and libyaml-perl packages, but still am getting the same error. What else is needed?
Config::YAML requires a different package. Install the libconfig-yaml-perl package and the problem will be fixed.
As the error says, something is missing in #INC. If you do have the module installed (perldoc -l YAML::Tiny for example) it might be installed in a location that is not added to #INC (see How is Perl's #INC constructed? (aka What are all the ways of affecting where Perl modules are searched for?) for how it's constructed).
That means that there could be something wrong with environment variables: if for example PERL5LIB is not set (or not set correctly), it could also cause this error.
For example, if Perl is installed in /home/myusername/perl5, setting PERL5LIB="/home/myusername/perl5/lib/perl5" can fix this (e.g. in your ~/.profile, don't forget to log out and in).
For reference, here is what my Perl installation had autogenerated:
PATH="/home/myusername/perl5/bin${PATH:+:${PATH}}"; export PATH;
PERL5LIB="/home/myusername/perl5/lib/perl5${PERL5LIB:+:${PERL5LIB}}"; export PERL5LIB;
PERL_LOCAL_LIB_ROOT="/home/myusername/perl5${PERL_LOCAL_LIB_ROOT:+:${PERL_LOCAL_LIB_ROOT}}"; export PERL_LOCAL_LIB_ROOT;
PERL_MB_OPT="--install_base \"/home/myusername/perl5\""; export PERL_MB_OPT;
PERL_MM_OPT="INSTALL_BASE=/home/myusername/perl5"; export PERL_MM_OPT;

Bioperl library installation in mysql server

I installed Bioperl and works correctly.
then installed Bio::Tools::Run::Phylo::Phyml and it works good from terminal.
But when I call same script contains it from a browser to using CGI method, I get this error:
Can't locate Bio/Tools/Run/Phylo/Phyml.pm in #INC (#INC contains:
/etc/perl /usr/local/lib/perl/5.14.2 /usr/local/share/perl/5.14.2
/usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.14
/usr/share/perl/5.14 /usr/local/lib/site_perl . /etc/apache2) at
/var/www/Adol/mafToPhyML1.pl line 14.\nBEGIN failed--compilation
aborted at /var/www/Adol/mafToPhyML1.pl line 14.
I got this message from error.log
This post is similar to your question. You need to properly set #INC in your cgi script. Add a use lib pragma to your cgi script with the directory that contains the Bio directory of where your Phyml.pm is located.

Can't locate *** in #INC

I install perl modules in ~/.local/perl5. Here's part of ~/.bashrc:
export PERL_LOCAL_LIB_ROOT="$HOME/.local/perl5";
export PERL_MB_OPT="--install_base $HOME/.local/perl5";
export PERL_MM_OPT="INSTALL_BASE=$HOME/.local/perl5";
export PERL5LIB="$HOME/.local/perl5/lib/perl5:$PERL5LIB";
export PATH="$HOME/.local/perl5/bin:$PATH";
I've installed CSS::Inliner with
$ cpan
cpan[1]> install CSS::Inliner
and I have Inliner.pm at:
~/.local/perl5/lib/perl5/CSS/Inliner.pm
But when I use it -- perl can't find it:
perl -e 'use Inliner'
gives:
Can't locate Inliner.pm in #INC (#INC contains:
/home/boris/.local/perl5/lib/perl5/x86_64-linux-gnu-thread-multi
/home/boris/.local/perl5/lib/perl5 /etc/perl
/usr/local/lib/perl/5.14.2 /usr/local/share/perl/5.14.2 /usr/lib/perl5
/usr/share/perl5 /usr/lib/perl/5.14 /usr/share/perl/5.14
/usr/local/lib/site_perl .) at -e line 1. BEGIN failed--compilation
aborted at -e line 1.
why can't perl find the module?
Edit:
I'm trying to reproduce minimal working example given in documentation to CSS-Inliner:
use Inliner;
my $inliner = new Inliner();
$inliner->read_file({filename => 'myfile.html'});
print $inliner->inlinify();
If I use Inliner -- perl can't find it. If I
#!/usr/bin/perl
use CSS::Inliner;
my $inliner = new Inliner();
$inliner->read_file({filename => 'test.html'});
print $inliner->inlinify();
perl says
Can't locate object method "new" via package "Inliner"
(perhaps you forgot to load "Inliner"?) at ./1.perl line 5.
Edit 2:
Here's a minimal working example of CSS-Inliner:
#!/usr/bin/perl
use CSS::Inliner;
my $inliner = CSS::Inliner->new;
$inliner->read_file({filename => 'test.html'});
print $inliner->inlinify();
You should use the full module name in use and full class name when calling class methods:
use CSS::Inliner;
my $inliner = CSS::Inliner->new;
This could happen when you are not careful in installing modules. Once I simply copied the foo.pm into the official /usr/lib/perl5/site_perl directory. The foo.pm could be modules developed locally or third party. I did not pay attention to the umask. Files installed there are not readable by the world. When I use the module I will get the message saying: Cannot locate foo.pm in #INC(#INC contains /usr/lib/perl5/site_perl ....). Gee it is clearly there! Took me a while to check the file permission. Hope this may save some time for others who install their own modules. In make file you should use install -m 644 to make sure the installed module has read permission for others.

Perl module not found

while I try to import a perl module into my script it says perl module not found.
#!/usr/bin/env perl
use lib 'mnt/hgfs/scripting/perl/perlib/Array';
use Shell;
#define all global variables here
use List::MoreUtils 'first_index';
use List::MoreUtils 'last_index';
use Getopt::Long;
use vars qw(%vectorList);
use Array::Compare;
I am getting the following error-
Can't locate Array/Compare.pm in #INC (#INC contains: mnt/hgfs/scripting/perl/perlib/Array /etc/perl /usr/local/lib/perl/5.10.1 /usr/local/share/perl/5.10.1 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl .) at wellbiasing.pl line 12.
BEGIN failed--compilation aborted at wellbiasing.pl line 12.
even though i have installed the Array module in perlib directory it says the module is not found.Array is a directory inside perlib directory which i had created to put all the modules inside the Array directory there is Compare.pm. but why is that I am not able to run it?
Change:
use lib 'mnt/hgfs/scripting/perl/perlib/Array';
to:
use lib 'mnt/hgfs/scripting/perl/perlib';
The Array directory should not be part of the Perl module search path.

Whats does the Perl error "Can't locate Net/SSH/Perl.pm" mean?

I am running a perl script that uses SSH, but it prints the following error:
Can't locate Net/SSH/Perl.pm in #INC (#INC contains: /etc/perl
/usr/local/lib/perl/5.10.1 /usr/local/share/perl/5.10.1 /usr/lib/perl5
/usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10
/usr/local/lib/site_perl .) at newone.pl line 3. BEGIN
failed--compilation aborted at newone.pl line 3.
Perl can't seem to locate Net/SSH/Perl.pm. Why can't it find it and how do I install it?
Your code is fine, although I haven't checked it as the error is due to a missing perl module.
What's the easiest way to install a missing Perl module?
You need to install and/or include the appropriate SSH library for perl. You can install it using this command:
cpan install Net::SSH::Perl