Unable to locate local file in #INC, not CPANable - perl

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";

Related

Remove entry from #INC

Is it possible to remove an entry from #INC from the command line?
I know export PERL5LIB=/path/file.pm can be used to add them, but can they be removed in a similar fashion?
EDIT:
I know that directories are not typically removed from #INC, but in my case (and maybe yours, if you are here for help) I added an entry of my own that I needed removed not only because it was a custom entry, but also because it specified a file (incorrect usage of #INC) and not a folder.
Additional Info:
The export command was executed from the command line, not from a script.
You could use the no lib pragma from the command line with perl -M-lib=...:
$ PERL5LIB=/tmp/foo perl -le 'print for #INC'
/tmp/foo
... normal #INC entries ...
$ PERL5LIB=/tmp/foo perl -M-lib=/tmp/foo -le 'print for #INC'
... normal #INC entries ...
Update: Based on the wording of the question, I assumed that you had a system where you had set PERL5LIB, and were asking how to exclude entries once in a while, only for specific runs of perl ("from the command line"). That's what the above does: The effect of no lib used on the command line is only temporary for that run of perl.
But the discussion in the comments revealed that it was the opposite: you had run export PERL5LIB=... "from the command line" (the effect of which is only temporary the current session/shell), and wanted to undo that change - for which the solution is either to run export PERL5LIB= (setting a new value overwrites the previous one, export is not like adding elements to a list, it just sets a new value), or to simply log out and back in again.
If you had set PERL5LIB in a place like the .profile or .bashrc files, then you would need to edit those and comment out or delete the entries you don't want, and log out and back in again.
You can change it in a BEGIN block. Example:
$ perl -MData::Dumper -e 'BEGIN { #INC = qw// }; print Dumper(\#INC);'
$VAR1 = [];

Library issue while using perl2exe

I am trying to convert my Perl script to standalone exe.
I assume perl2exe is a tool that serves this purpose. More or less.
When I am trying to generate the exe file, I am getting library issues.
One of the library issues is:
Warning: Can't locate VMS/Stdio.pm
at C:\Perl\lib\File\Temp.pm line 19
#INC = C:\Perl\site\lib, C:\Perl\lib, ., C:\Perl\lib\Digest, must be directory, not file)
When I went to line 19 of Temp.pm, the line is written as follows:
require VMS::Stdio if $^O eq 'VMS';
But,my OS is MSWin32.
I am coming to a conclusion that, perl2exe is not compiling the script properly. Its reading my OS wrong.
Sample script is as follows:
my_libraries.pl
use Tk;
use lib 'C:\Perl\lib\Digest';
use strict;
use strict;
use warnings;
use strict;
use warnings;
use LWP::Simple qw(getstore);
use LWP::UserAgent;
use Digest::MD5 qw( md5_hex );
use Digest::MD5::File qw( file_md5_hex );
use File::Fetch;
use WWW::Mechanize ;
use Tk::ErrorDialog;
c:\perl2exe\perl2exe-16.00-Win> perl2exe my_libraries.pl my_libraries.exe
Warning: Can't locate File/BSDGlob.pm
at C:\Perl\lib\File\GlobMapper.pm line 13
#INC = C:\Perl\site\lib, C:\Perl\lib, ., C:\Perl\lib\Digest, must be directory, not file)
Warning: Can't locate Digest/Perl/MD5.pm
at C:\Perl\lib\Digest\MD5.pm line 30
#INC = C:\Perl\site\lib, C:\Perl\lib, ., C:\Perl\lib\Digest, must be directory, not file)
Warning: Can't locate VMS/Stdio.pm
at C:\Perl\lib\File\Temp.pm line 19
#INC = C:\Perl\site\lib, C:\Perl\lib, ., C:\Perl\lib\Digest, must be directory, not file)
Warning: Can't locate VMS/DCLsym.pm
at C:\Perl\lib\IPC\Cmd.pm line 227
#INC = C:\Perl\site\lib, C:\Perl\lib, ., C:\Perl\lib\Digest, must be directory, not file)
Warning: Can't locate VMS/Filespec.pm
at C:\Perl\lib\ExtUtils\Manifest.pm line 31
#INC = C:\Perl\site\lib, C:\Perl\lib, ., C:\Perl\lib\Digest, must be directory, not file)
Warning: Can't locate HTML/FormatText.pm
at C:\Perl\lib\HTML\Element.pm line 1297
#INC = C:\Perl\site\lib, C:\Perl\lib, ., C:\Perl\lib\Digest, must be directory, not file)
Sorry. let me put my obvious question here:
Why is perl2exe giving library issues which are not intended to come? Is it a bug in perl2exe or am I doing something wrong?
I mean, you can see in line 19 that if the OS is 'VMS', then stdio.pm is required. My os is 'MSWin32'.
I tried a to z possible remediation to make the perl2exe work. I removed the sections that was producing warnings (Hacked the modules). Studied and tried various flags. I have to say it is not at all feasible to convert Perl programs using diverse modules to exe files using perl2exe.
I found a software that exactly did what I wanted- Cava Packager.
It took sometime to find the below page-
How can I package my Perl script to run on a machine without Perl?
It converted my Perl program to Exe and also generated an installation file. Awesome.
Thanks,
Anoop.
The problem is
C:\Perl\lib\File\Temp.pm line 19
Open the file you will see this
require VMS::Stdio if $^O eq 'VMS';
Change the file not read-only, then place # for this line, go back to perl2exe the file again, then it should be gone.
It may be of interest to readers of this issue that in addition to the VMS/Stdio.pm error, I also received "Can't locate the.pm". The line in my perl code that it pointed to was the text "Use the 't' command..." that was inside a double-quoted print statement. Apparently perl2exe looked for the 'use' statement regardless of where in my code it appeared. The fix was to either re-word the text to remove the word 'use' or put the text in single quotes.

Change the position of program lead to syntax error

I have a program called shuffle.pl . When I use perl shuffle.pl Input Shuffled to execute , it success work and show no error .
I create a directory called ./tools under my home directory , and I set this path to .cshrc . So I can execute the program without typing perl to execute . ( This is my first time to do this , maybe some wrong in here)
But when I move the shuffle.pl to ~/.tools and execute . it show I have error in line 5 . But if I use perl ~/.tools/shuffle.plit can work . So it means it should have no syntax error in my program ,But why it can't work after I put my program to ~/.tools
error message
.tools/shuffle.pl: 5: Syntax error: "(" unexpected
.cshrc
set path = (. ~ ~/.tools /sbin /bin /usr/sbin /usr/bin /usr/games /usr/local/sbin /usr/local/bin )
thanks
here is my program
#!/usr/bin/perl
use strict;
use warnings;
use List::Util qw(first max maxstr min minstr reduce shuffle sum);
open(my $fh,"<","$ARGV[0]");
my #Lines = readline($fh);
my #Shuffled = shuffle(#Lines);
close $fh;
open(my $shuf,">","$ARGV[1]");
print $shuf #Shuffled;
close $shuf;
The shebang is used to tell which interpreter should be used for this script. For this to work, the magic number #! has to appear at the immediate beginning of the file. Otherwise, the default interpreter is used.
In this case, the shebang was preceded by a few empty lines. They have to be removed.
The shebang is not parsed when an explicit interpreter is used to execute the file, E.g. in $ perl script.pl.
It is only important when launched as executable: ./script.pl. In that case, the kernel is left to figure out what to do with it: Load into memory as compiled program? Launch an interpreter? Which one? Magic numbers like #! resolve this.
In general, if the shebang doesn't work, the following possible errors can be checked:
An UTF byte order mark precedes the #!.
Diagnosis: A hexdump shows FE FF at the beginning.
Solution: configure your editor to store files without a BOM
The script is encoded in such a way that the beginning does not decode to #! as ASCII.
Diagnosis: The file does not begin with #! when opened as ASCII or does not begin with 23 21 in a hexdump. Or your editor shows UTF-16 or UTF-32 as the encoding.
Solution: Store the script in ASCII-compatible encoding. UTF-8 is an especially good choice.
Non-native line endings can be confused to be part of the executable name. E.g. with windows line endings, the shebang in
#!/usr/bin/perl
print 1;
could be taken as the interpreter name "/usr/bin/perl\r". Many filesystems allow line endings inside filenames.
Diagnosis: A hexdump shows something other than a space (20) or newline (0A) after the executable name.
Solution: Convert line endings to Unix.
A few general tips:
You should have -w on the shebang line to catch warnings.
You should probably use strict; also.
Don't put double quotes around "$ARGV[0]" and "$ARGV[1]" because they serve no purpose.
Use "do or die" syntax on the file opens, e.g.:
open (File, "<", $ARGV[0]) || die "File open error: $!";
Do those things and I am pretty sure the solution will appear rapidly.

Creating a table in 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

gvim can't locate the Perl modules

I'm trying to write a function in gvim that would use the module File::Path.But
it alert me "Can't locate File/Path.pm in #INC(#INC contains: .) at (eval 8) line 1.
BEGIN failed--compilation aborted at (eval 8) line 1." when gvim start.
I know it means gvim couldn't find my perl lib path.
So,my question was :
How to tell gvim the correct path to locate the Perl modules?I have tried to add use lib'C:/Perl/lib'; but the problem continued.
Thank you~~~
if has("perl")
function! Make_dir()
perl make_dir();
endfunction
autocmd VimEnter * call Make_dir()
perl <<EOF
use File::Path;
sub make_dir{
my $bakup=$ENV{'HOME'}."/bakup" ;
mkdir $bakup if not -e _;
#VIM::SetOption("backup");
#VIM::SetOption("backupdir=$bakup");
#VIM::Msg($bakup);
#todo....
}
EOF
endif
Did you "censor" your output, or does it really say just "(#INC contains: .)"? That would seem to indicate a bad installation of Perl. It should have a few more directories in there. It could indicate a permission problem, I imagine.
use lib doesn't work because Perl can't find lib.pm or any other module it comes with. -I should work though, but it would only be a bandaid fix.
http://vim.wikia.com/wiki/Script:556
BTW,I tried the way on vim tips wiki also...but the problem continued