installing perl in windows 7 - perl

I am pretty layman to Perl, never used it ...but now I want to use it.
Here is what I did:
http://www.activestate.com/activeperl/downloads
I installed universal version - 5.12.4.1205
To test my program is working, I used the following small program :
dnacon.plx
#i/Perl64/bin/perl -w
#Example 1-1 Concatenating DNA
$DNA1 = 'ATTTGGTAAAATGTATA'
$DNA2 = 'TTTTGGGTTTGAAAT'
print "Here are two DNA fragments: \n\n"
print $DNA1, "\n\n"
print $DNA2, "\n\n"
$DNA3 = "$DNA1$$DNA2"
print "$DNA3\n\n
When I try to execute it the following is command prompt with errors.
Sorry for too basic question...
EDTIS:
When I just type dnacon.plx, it is seems that it is working, but with error !!!
c:\myperllessions>dnacon.plx
Scalar found where operator expected at C:\myperllessions\dnacon.plx line 5, nea
r "$DNA2"
(Missing semicolon on previous line?)
syntax error at C:\myperllessions\dnacon.plx line 5, near "$DNA2 "
Execution of C:\myperllessions\dnacon.plx aborted due to compilation errors.
Am I good to go ??? What could be the error ...compilation errors ????
Edits:
I am using the following now : is this correct ?
#i/Perl64/bin -w
Edits:
I changed my script to following:
#i/Perl64/bin -w
#Example 1-1 Concatenating DNA
use strict;
use warnings;
$DNA1 = 'ATTTGGTAAAATGTATA';
$DNA2 = 'TTTTGGGTTTGAAAT';
print "Here are two DNA fragments: \n\n";
print $DNA1, "\n\n";
print $DNA2, "\n\n";
$DNA3 = "$DNA1$$DNA2";
print "$DNA3\n\n";
I got the following error:
c:\myperllessions>dnacon.plx
Global symbol "$DNA1" requires explicit package name at C:\myperllessions\dnacon
.plx line 5.
Global symbol "$DNA2" requires explicit package name at C:\myperllessions\dnacon
.plx line 6.
Global symbol "$DNA1" requires explicit package name at C:\myperllessions\dnacon
.plx line 9.
Global symbol "$DNA2" requires explicit package name at C:\myperllessions\dnacon
.plx line 10.
Global symbol "$DNA3" requires explicit package name at C:\myperllessions\dnacon
.plx line 12.
Global symbol "$DNA1" requires explicit package name at C:\myperllessions\dnacon
.plx line 12.
Global symbol "$DNA2" requires explicit package name at C:\myperllessions\dnacon
.plx line 12.
Global symbol "$DNA3" requires explicit package name at C:\myperllessions\dnacon
.plx line 13.
Execution of C:\myperllessions\dnacon.plx aborted due to compilation errors.
Is my problem now with programming knowledge or something to do with installation ?????

To get perl to be recognized, you must add C:\Perl64\bin to the PATH environment variable. Go to Control Panel > System > Advanced System Settings > Environment Variables. Edit the line containing PATH in the top box marked User variables for <user>, and add ;C:\Perl64\bin (note the semicolon) to the end. Be sure not to corrupt anything that's already there.
The problems you are left with in your latest edit - Global symbol requires explicit package name - are because you have added use strict (a very good thing to do) and you haven't declared your variables. Also the line #i/Perl64/bin -w won't do anything and may as well be removed. Write this instead
use strict;
use warnings;
my $DNA1 = 'ATTTGGTAAAATGTATA';
my $DNA2 = 'TTTTGGGTTTGAAAT';
print "Here are two DNA fragments: \n\n";
print $DNA1, "\n\n";
print $DNA2, "\n\n";
my $DNA3 = "$DNA1$$DNA2";
print "$DNA3\n\n";

Did you try out Strawberry perl? It takes care of setting up the environment vars for you.

An environment variable may not be set up yet.
Since I no longer use Windows, I cannot give you the exact step by step instructions, but I can tell you, that somewhere in System Properties, you'll find a place to edit the environment variables.
Edit the path variable and append 'C:\Perl64\bin\' to it.
P.S.:This is assuming that when you cd to the said path, you are able to run the perl program. If not, something is wrong with the installation. Try re-installing Perl.

Related

Perl state variable requires explicit package name

I am having problems getting state variables to work. I have extensive experience with "my" variables, but getting "state" variables to work hasn't been easy.
Here is a bare minimum example to reproduce the problem:
$ perl -e 'use strict; sub test {state $string = ""; print $string; }'
Global symbol "$string" requires explicit package name (did you forget to declare "my $string"?) at -e line 1.
Global symbol "$string" requires explicit package name (did you forget to declare "my $string"?) at -e line 1.
Execution of -e aborted due to compilation errors.
$ perl --version
This is perl 5, version 32, subversion 1 (v5.32.1) built for MSWin32-x64-multi-thread
According to the documentation for the state keyword:
state is available only if the "state" feature is enabled or if it is
prefixed with CORE::. The "state" feature is enabled automatically
with a use v5.10 (or higher) declaration in the current scope.
Here is one way to change your one-liner to avoid the error:
$ perl -e 'use strict; use feature "state"; sub test {state $string = ""; print $string; }'
The docs mention:
This feature is available starting with Perl 5.10.
Although you are using Perl version v5.32.1, which is later than 5.10, it is still necessary to explicitly enable the state feature using one of the methods shown in the documentation. This feature is currently not enabled by default for any version of Perl.

Perl in Intellij IDEA: Global symbol "%Config" requires explicit package name (did you forget to declare "my %Config"?) lib.pm

I'm developing a large perl module which works like a charm when running from Terminal. When running i with Intellij IDEA CE, the following error pops up. This happens in all major versions of the software.
My programm starts:
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use feature qw (say);
use Getopt::Long;
use lib 'lib';
die('this is a test');
...
Perls own lib.pm starts like this
package lib;
# THIS FILE IS AUTOMATICALLY GENERATED FROM lib_pm.PL.
# ANY CHANGES TO THIS FILE WILL BE OVERWRITTEN BY THE NEXT PERL BUILD.
use Config;
use strict;
my $archname = $Config{archname};
my $version = $Config{version};
my #inc_version_list = reverse split / /, $Config{inc_version_list};
our #ORIG_INC = #INC; # take a handy copy of 'original' value
our $VERSION = '0.65';
...
In Intellij IDEA this leads to
/usr/bin/perl -I/home/user/git/mytool/lib -I/home/user/git/mytool/lib/Download /home/user/git/mytool/download.pl Digi20
Global symbol "%Config" requires explicit package name (did you forget to declare "my %Config"?) at /usr/lib/x86_64-linux-gnu/perl-base/lib.pm line 10.
Global symbol "%Config" requires explicit package name (did you forget to declare "my %Config"?) at /usr/lib/x86_64-linux-gnu/perl-base/lib.pm line 11.
Global symbol "%Config" requires explicit package name (did you forget to declare "my %Config"?) at /usr/lib/x86_64-linux-gnu/perl-base/lib.pm line 12.
Compilation failed in require at /home/user/git/mytool/download.pl line 10.
I don't know where these -I params to the perl executable are configured. In the run dialog, i configured no params for perl.
Ubuntu 22.04 LTA + Perl 5.34. On my home office machine everything works fine, too. But on the office machine not. Syncing IDE settings home > office does not help.
Found another user having a similar issue on Eclipse but the error comes from another module. My Config module is already named Download::Config.
There's a module call Config that comes with Perl. It exports a hash named %Config by default.
The error is due to %Config not being exported by by use Config;.
I'm guessing a different module named Config is being picked up by use Config;. You can verify this using BEGIN { print "$INC{'Config.pm'}\n" } after the use Config;.
You should name your module something else.
That said, I suspect you don't actually have a module named Config. I suspect you have a module named Download::Config (which is perfectly fine), but /home/user/git/mytool/lib/Download is being incorrectly added to #INC.
I found the solution:
Intellij IDEA adds the configured library destinations as -I param to the perl call. Mind the purple marker here in the picture. The Download folder was purple, too. That caused the error.
There is a similar setting in the project structure settings but this does not cause -I parameters being added.

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.

My first perl script is generating an error

my perl script is:
#!/usr/bin/perl -w
use strict ;
use warnings;
print "Hello $name \n"
I get this error:
Global symbol "$name" requires explicit package name at fst_pscpt.pl.
This is really stopping my progress.do we need to include any packages???
Thanks & Regards,
B.Raviteja
You haven't declared any variable $name. So you'll need to get that variable somehow. For example, if you wanted to get it from the command line, you could do this:
#!/usr/bin/perl -w
use strict;
use warnings;
my $name = $ARGV[0];
print "Hello, $name!\n";
And then call your program like so:
./myprog.pl Rafe
And get the output:
Hello, Rafe!
Also, you don't have a semicolon at the end of the last line. You'll need that as well.
diagnostics gives you more useful help in this case:
$ perl -Mdiagnostics fst_pscpt.pl
Global symbol "$name" requires explicit package name at fst_pscpt.pl line 4.
Execution of fst_pscpt.pl aborted due to compilation errors (#1)
(F) You've said "use strict" or "use strict vars", which indicates
that all variables must either be lexically scoped (using "my"),
declared beforehand using "our", or explicitly qualified to say
which package the global variable is in (using "::").
Uncaught exception from user code:
Global symbol "$name" requires explicit package name at fst_pscpt.pl line 4.
Execution of fst_pscpt.pl aborted due to compilation errors.
at fst_pscpt.pl line 5
You need to declare $name when you use strict; (which includes strict vars). Just insert the line:
my $name;
before using it.

How can I use Perl 5.10 features inside the debugger?

I am unable to evaluate 'modern Perl' code inside the Perl debugger. It works OK when debugging the code in a file, but not from the prompt.
Minimal example:
# Activating 5-10 features with -E (it works)
$ perl -E 'say "x"'
x
# Calling the debugger with -E
# It works for infile code, but for prompt line code...
$ perl -dEbug Loading DB routines from perl5db.pl version 1.33
DB say "x"
String found where operator expected at (eval 16)[/local-perl/lib/5.12.1/perl5db.pl:638] line 2, near "say "x""
at (eval 16)[/local-perl/lib/5.12.1/perl5db.pl:638] line 2
eval '($#, $!, $^E, $,, $/, $\\, $^W) = #saved;package main; $^D = $^D | $DB::db_stop;say "x";
(Note: the same happens with "use feature ':5.10'".)
Am I missing something?
I found a reference to the issue here, but it's about a year old. However, the relevant portion of the Perl source hasn't changed since and can be seen here. Essentially, if you take a look at toke.c in the Perl source, you see the following:
if (PL_perldb) {
/* Generate a string of Perl code to load the debugger.
* If PERL5DB is set, it will return the contents of that,
* otherwise a compile-time require of perl5db.pl. */
const char * const pdb = PerlEnv_getenv("PERL5DB");
...
}
...
if (PL_minus_E)
sv_catpvs(PL_linestr,
"use feature ':5." STRINGIFY(PERL_VERSION) "';");
Basically, the debugger is loaded before the -E flag is processed, so the features aren't yet enabled when the debugger gets loaded. The gist of this is that you can't currently use -E with the -d command. If you want to use say, switch, or any other feature from the debug prompt, you have to do it like this:
DB<1> use feature 'say'; say "x"
x
The closest I've seen to a solution is:
copy perl5db.pl from your PERL5LIB to either somewhere in PERL5LIB or the current directory, with a different name, say myperl5db.pl
2. Edit myperl5db.pl to have use feature ':5.10'; (or just 'state', or just 'say') on the first line.
3. Set the environment variable PERL5DB to "BEGIN { require 'myperl5db.pl' }"
Which I found at PerlMonks.