Creating a table in perl - perl

use Text::Table;
my $tb = Text::Table->new(“Planet”,”Radius\nkm”,”Density\ng/cm^3”);
$tb->load(
[ “Mercury”,2360,3.7],
[ “Mercury”,2360,3.7],
[ “Mercury”,2360,3.7],
);
Print $tb;
I'm executing the above perl snippet to create the table with the data. But i'm getting an error as
Can't locate Text/Table.pm in #INC (#INC contains: C:/Perl64/site/lib C:/Perl64/
lib .) at table.pl line 1.
BEGIN failed--compilation aborted at table.pl line 1.
I'm using Activeperl,Selenium RC. Should i need to download any packages for the table ?
or any other better ways to create a table apart from this ?

The most common reason for Perl not being able to find a module is because it's not installed. Try
ppm install Text::Table
or if it fails,
cpan Text::Table
Note that your code is invalid. You tried to use
“, U+201C, LEFT DOUBLE QUOTATION MARK, and
“, U+201D, RIGHT DOUBLE QUOTATION MARK
but the quote character you need to use is
", U+0022, QUOTATION MARK

Related

Perl CPAN Can't locate CPAN/Author.pm... when trying to install nipe

I'm trying to install "nipe" on my Windows Machine but i get this error code all the time. I have installed Strawberry Perl.
This is the error code:
Can't locate CPAN/Author.pm in #INC (you may need to install the CPAN::Author module) (#INC contains: /usr/lib/perl5/site_perl /usr/share/perl5/site_perl /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5/core_perl /usr/share/perl5/core_perl) at /usr/share/perl5/core_perl/CPAN.pm line 19.
BEGIN failed--compilation aborted at /usr/share/perl5/core_perl/CPAN.pm line 19.
Compilation failed in require at /usr/share/perl5/core_perl/App/Cpan.pm line 290.
BEGIN failed--compilation aborted at /usr/share/perl5/core_perl/App/Cpan.pm line 290.
Compilation failed in require at /c/Strawberry/perl/bin/cpan line 7.
BEGIN failed--compilation aborted at /c/Strawberry/perl/bin/cpan line 7.
While you may have Strawberry Perl installed, that's not the perl you are using. C:\Strawberry\perl\bin\cpan uses the first perl in your PATH, which isn't your installation of Strawberry Perl. It appears that you are using some unix emulation (Cygwin? MSYS?) and using the perl from that emulation.
To use your Strawberry Perl build of perl, you could adjust your PATH so that SP comes before whatever perl you ended up using, or you could use
C:\Strawberry\perl\bin\perl C:\Strawberry\perl\bin\cpan Try::Tiny Config::Simple JSON
or
C:\Strawberry\perl\bin\perl -MCPAN -e"install #ARGV" Try::Tiny Config::Simple JSON
in lieu of
cpan Try::Tiny Config::Simple JSON
Similarly, if you don't adjust your path, you'll need to use
C:\Strawberry\perl\bin\perl nipe.pl ...
in lieu of
perl nipe.pl ...
If your are using windows and a bash then try to it with cmd or powershell after you applied the changes from #ikegami. Took me some time to figure out, that it had no effect to change the paths for this terminal, as it still took the paths from /usr//perl5/
I tried to do all of the other answers, but it didn't work. Instead it appeared that it doesn't work because I tried to run it from unix shell script (sh in powershell or git bash). After moving it from .sh to .ps1 and running non-unix way it works perfectly.

Unable to locate local file in #INC, not CPANable

I'm am currently trying to download a program that has given me many issues. I'm running cygwin on Windows. The program should run correctly and the installation packages were all installed in an administrator terminal shell, and as the program was being un'tar'ed no errors were thrown. However after the installation the program cannot find the #INC module named FASTA in the file system
rpbas#DESKTOP-4LMFDCK /cygdrive/c/Users/rpbas/Documents/Work/OliveraLab/signal-4.1
$ ./signal -t euk -f short test/euk10.fsa > euk10.fsa.short_out Can't locate FASTA.pm in #INC (you may need to install the FASTA module)
(#INC contains:
/cygdrive/c/Users/rpbas/Documents/Work/Olivera\ Lab/signal-4.1/lib
\cygdrive\c\Users\rpbas\Documents\Work\Olivera/ Lab\signal-4.1
/usr/local/lib/perl5/site_perl/5.26/x86_64-cygwin-threads
/usr/local/share/perl5/site_perl/5.26 /usr/lib/perl5/vendor_perl/5.26/x86_64-cygwin-threads
/usr/share/perl5/vendor_perl/5.26
/usr/lib/perl5/5.26/x86_64-cygwin-threads /usr/share/perl5/5.26)
at ./signal line 60.
BEGIN failed-- compilation aborted at ./signal line 60.
However, the ./lib/FASTA.pm file clearly exists and being directed to.
rpbas#DESKTOP-4LMFDCK /cygdrive/c/Users/rpbas/Documents/Work/Olivera\ Lab/signal-4.1/lib
$ ls
FASTA.pm
The code includes the line (at the beginning)
BEGIN {
$ENV{SIGNAL} = '/cygdrive/c/Users/rpbas/Documents/Work/Olivera\ Lab/signal-4.1';
}
and at line 60
use lib "$ENV{SIGNAL}/lib";
use FASTA;
I've been working on this issue for a couple of days now and it a big bottleneck to the other parts of my program. Any help would be appreciated!
You are getting tripped up by the quote interpolation rules of Perl. Inside single quotes, a backslash character only acts as an "escape" character when it is followed by a single quote or by another backslash. In all other cases, it is interpreted as a literal backslash.
If you printed out $ENV{SIGNAL} you would see something like
/cygdrive/c/Users/rpbas/Documents/Work/Olivera\ Lab/signal-4.1
including the backslash character. Don't escape the space and you should be all right.
BEGIN {
$ENV{SIGNAL} =
'/cygdrive/c/Users/rpbas/Documents/Work/Olivera Lab/signal-4.1';
}
#INC contains
/cygdrive/c/Users/rpbas/Documents/Work/Olivera\ Lab/signal-4.1/lib
when it should contain
/cygdrive/c/Users/rpbas/Documents/Work/Olivera Lab/signal-4.1/lib
You could replace
BEGIN {
$ENV{SIGNAL} = '/cygdrive/c/Users/rpbas/Documents/Work/Olivera\ Lab/signal-4.1';
}
use lib "$ENV{SIGNAL}/lib";
with
BEGIN {
$ENV{SIGNAL} = '/cygdrive/c/Users/rpbas/Documents/Work/Olivera Lab/signal-4.1';
}
use lib "$ENV{SIGNAL}/lib";
but a better solution is to replace it with
use FindBin qw( $RealBin );
use lib ( $ENV{SIGNAL} || $RealBin ) . "/lib";

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.

Can't locate XML/XPath.pm in #INC

I have a .pl script in which starts by:
#!/usr/bin/perl
use XML::XPath;
use Getopt::Long;
I can't seem to run that via perl myScript.pl, having this error:
(#INC contains: /usr/share/ /usr/local/lib64/perl5 /usr/local/share/perl5/usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at most_generic_wrapper.pl line 3.
BEGIN failed--compilation aborted at myScript.pl line 3.
1- I tried to locate the XPath.pm file and export that as:
export PERL5LIB=/usr/share/perl5/XML/Twig
and
export PERL5LIB=/usr/share/perl5/XML
2- Installed perl -MCPAN -e 'install XML::Parser'
3- Used -I to explicitly define the path as:
perl -I perl -MCPAN -e 'install XML::Parser' myScript.pl
4- changing the line 3 to use XML::Twig::XPath; led to:
cannot use XML::Twig::XPath: neither XML::XPathEngine 0.09+ nor XML::XPath are available at /usr/share/perl5/XML/Twig/XPath.pm line 11.
BEGIN failed--compilation aborted at /usr/share/perl5/XML/Twig/XPath.pm line 13.`
But none of them solved the issue and I keep receiving the same error at line.3.
P.S: Running on CentOS 6.2 with the kernel 2.6.32-358 and perl --version=v5.10.1 (*) built for x86_64-linux-thread-multi
Any helps would be appreciated,
Your title says XML::XPath can't be found, but your question indicates you tried to install XML::Parser. Did you try to install XML::XPath?
From man perlrun: "If PERL5LIB is not defined, PERLLIB". You seem to have tried setting PERLIB5 (notice the spelling difference: the var is PERL5LIB (or PERLLIB), not PERLIB5).
From man perlrun: "PERL5LIB -- A list of directories in which to look for Perl library files before looking in the standard library and the current directory." You seem to have tried setting it to the full path to a .pm file, rather than a directory.
The file you assigned would be XML::Twig::XPath, not XML::XPath; those are two different Perl modules.
Edit: After looking at your revised question:
I'm not sure if your script requires XML::Twig::XPath or XML::XPath, or if either one can provide the API you need. However, XML::Twig::XPath seems to depend on XML::XPath so you will need XML::XPath no matter what, and it looks like XML::XPath is not installed on your system. I think that's probably the main problem. Please try to install XML::XPath using CPAN.
The value of the PERL5LIB variable (or the argument to the -I option) should be the directory that sits at the base of the package-qualified module file. For example, if XML::XPath is located at ~/perl_custom_modules/XML/XPath.pm, then you need to set PERL5LIB (or the -I argument) to ~/perl_custom_modules. The XML directory is part of the package qualification of the module, so does not need to be included in the include path.

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.