Perl - Error : Cant locate file in #INC - perl

As I am Novice to Perl, I would be happy if you are able to solve my problem.
I created a Module named "Messages.pm" and it resides in the path "E:\Venkadachalam\Perl_samples\Modules\Messages.pm"
Also I included this module in another Perl file named "Main.pl" as show below
use Modules::Messages;
and invoked the subroutine defined in the Messaged.pm in the Main.pl
In the Command Window, I tried executing the above perl program as
perl -I E:\Venkadachalam\Perl_samples\Modules\Messages.pm Main.pl
Here it gives an error message as shown below:
"Can't locate Modules/Messages.pm in #INC (#INC contains: E:/Venkadachalam/Perl_s
ample/Modules C:/Perl/site/lib C:/Perl/lib .) at Main.pl line 1
BEGIN failed--compilation aborted at Main.pl line 1"
Any help is highly appreciated.

You are saying use Modules::Messages; and pointing the lib to E:/Venkadachalam/Perl_sample/Modules. So it is expecting lib to be E:/Venkadachalam/Perl_sample/Modules/Modules/Messages.pm.
Change it to E:/Venkadachalam/Perl_sample
Doc

Related

Can I move perl modules without breaking the system?

I have the exact problem described here:
Perl can't find module when run from cron.daily except that my problem applies to a perl script running from crontab.
In my case the error message is:
May 24 22:12:02 trackcam3 test_cron: Can't locate Image/Grab.pm in #INC (you may need to install the Image::Grab module) (#INC contains: /etc/perl /usr/local/lib/arm-linux-gnueabihf/perl/5.24.1 /usr/local/share/perl/5.24.1 /usr/lib/arm-linux-gnueabihf/perl5/5.24 /usr/share/perl5 /usr/lib/arm-linux-gnueabihf/perl/5.24 /usr/share/perl/5.24 /usr/local/lib/site_perl /usr/lib/arm-linux-gnueabihf/perl-base) at /home/darren/upload_image.pl line 33, <DATA> line 1.
May 24 22:12:02 trackcam3 test_cron: BEGIN failed--compilation aborted at /home/darren/upload_image.pl line 33, <DATA> line 1.
The solutions at the link all add something to the path. I would like to know if I can move or copy the modules to somewhere they can be found when perl scripts from crontab.
As part of troubleshooting I have already loaded cron with the same PATH as I have from the terminal but that is not enough to allow the perl module to be found.
The missing module is in ~/perl5/lib/perl5 which is not in #INC
The same perl script call modules that are located at
/usr/lib/arm-linux-gnueabihf/perl5/5.24/Image/Magick
Should it be somewhere else? At present /usr/lib/perl5 is empty. The OP in the link asked the same question in the link but didn't receive an answer.
Try:
use lib glob( '~/perl5/lib/perl5' );
use Image::Grab;
The use lib must come before many use module.
Follow the link in the following comment by #haukex to arrive at a full explanation.

now function for displaying Date and Time not working through ActivePerl

I want to display the present date and time in perl using now() function. I am running this script using Active Perl software but I am getting error.
#! /usr/bin/perl
use Date::Parse;
$date = str2time(now());
print "$date\n";
I am getting error as:
C:\Users\admin\Desktop>perl test.pl
Can't locate Date/Parse.pm in #INC (#INC contains: C:/Perl/site/lib C:/Perl/lib
.) at test.pl line 3.
BEGIN failed--compilation aborted at test.pl line 3.
Please help.
You do not have module Date::Parse installed by default in ActivePerl.
You can fix this with:
ppm install Date::Parse
This works for me for ActivePerl 5.16 default install.

Getting error "Can't locate HTML/TreeBuilder/XPath.pm in #INC "

Gettin below error while running my perl file
Can't locate HTML/TreeBuilder/XPath.pm in #INC (#INC contains: C:/Perl/lib C:/Pe
rl/site/lib .) at display.pl line 4.
BEGIN failed--compilation aborted at display.pl line 4.
HTML::TreeBuilder::XPath module(0.14) is installed. From command line when i run command
perl -e HTML::TreeBuilder::XPath it doesn't give any error.
when i run from command line perldoc -l HTML::TreeBuilder::XPath gives below error:
No documentation found for "HTML::TreeBuilder::XPath".
My perl version is 5.8.7
First cross check does this module is really installed ? I think it is not installed, install it from cpan.

Error using bytecode-compiling filter, PERL

When I compile using: pp -I lib -f Bytecode -o myapp_binary_bytecode myapp
I get this error:
"my" variable $fh masks earlier declaration in same scope at /Library/Perl/5.12/PAR/Filter/Bytecode.pm line 60.
Can't locate B/Bytecode.pm in #INC (#INC contains: /Library/Perl/5.12/darwin-thread-multi-2level /Library/Perl/5.12 /Network/Library/Perl/5.12/darwin-thread-multi-2level /Network/Library/Perl/5.12 /Library/Perl/Updates/5.12.3/darwin-thread-multi-2level /Library/Perl/Updates/5.12.3 /System/Library/Perl/5.12/darwin-thread-multi-2level /System/Library/Perl/5.12 /System/Library/Perl/Extras/5.12/darwin-thread-multi-2level /System/Library/Perl/Extras/5.12 .) at (eval 1) line 18.
BEGIN failed--compilation aborted at (eval 1) line 18.
BEGIN failed--compilation aborted.
Cannot transform /var/folders/cd/rwsp63c15bb01r89z76_bvr40000gn/T/Q3ubgSUe8P to /var/folders/cd/rwsp63c15bb01r89z76_bvr40000gn/T/LIcOpNf_Oh: No such file or directory (512)
Although the compiled binary works, but how can I fix the error?
Thanks!
The error says you're trying to use a module Perl can't locate. The usual cause is that you don't have that module installed.
A lack of permissions to read the module file could also lead to that error, but that's almost never the problem.
Unrelatedly, I would look into that my problem. As to why the running binary still has that problem, pp can easily miss dependencies, but it has a dynamic way to counter that problem. Try running pp -x script and it will run the script to find any run-time dependencies. Also I think there's a switch for manually adding dependencies to the list.

Can't locate File/Glob.pm in #INC (#INC contains: D:/tools/lib .) at directory.pl line 2

I get this error when running my perl code
Can't locate File/Glob.pm in #INC (#INC contains: D:/tools/lib .) at directory.pl line 2.
line 2: #files=<*>;
When i run the command, I get,
Y:\perl\perl>perldoc -l File::Glob
D:\tools\lib\perl\510\File\Glob.pm
So I think the File::Glob module is installed?
#INC should be set correctly upon installation of Perl. When it doesn't match your configuration, you seem to have messed up something.
However, if the current value of #INC doesn't fit your needs, you have various options:
Add D:\tools\lib\perl\510\ to the
environment variable PERL5LIB (or PERLLIB if this doesn't work)
Specify #INC on startup:
perl -I D:\tools\lib\perl\510\
Instead of writing use libname, you can write use path/to/libname
Using a BEGIN block before the use statements:
BEGIN {
push #INC,"D:\tools\lib\perl\510\";
}
See also http://perldoc.perl.org/perlvar.html for a short introduction.