2

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.

enter image description here

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 ?????

jon
  • 11,186
  • 19
  • 80
  • 132
  • Does using the full path to `perl` work? `C:\Perl64\bin\perl`? – Ry- Feb 26 '12 at 15:13
  • C:\Perl64\bin is where the perl.exe is located at – jon Feb 26 '12 at 15:19
  • Yes. Does using that instead of just typing `perl` work? – Ry- Feb 26 '12 at 15:19
  • I tried both C:\Perl64\bin\ and C:\Perl64\bin same error message – jon Feb 26 '12 at 15:25
  • Try see if that directory appears if you do `echo %PATH%`. – TLP Feb 26 '12 at 15:27
  • And by the way, if your install is correct, you should not have to write out `perl` when executing a script. The file extension should be associated with the perl binary. – TLP Feb 26 '12 at 15:30
  • @JohnC I assume you did see *some* paths in there? Like `C:\Windows;C:\Windows32;...`. I'm not sure if Win7 uses the same path variable as XP. If windows cannot find the perl binary, it cannot execute it, and I would assume something went wrong with your installation. – TLP Feb 26 '12 at 15:42
  • 1
    @JohnC Well, you do need semi-colons to end the statements in your code... And you might want to `use strict; use warnings;`. In your concatenation, you refer to `$$DNA2`, which of course is incorrect, as it will try to dereference `TTTTGGGTTTGAAAT` into a scalar variable. Nonetheless, it should recognize `perl` as a command. – TLP Feb 26 '12 at 15:45
  • @ TLP, Yes I did see paths but not the C:\Perl64\bin – jon Feb 26 '12 at 15:46
  • @JohnC You don't need a shebang (the `#!` first line) in windows. – TLP Feb 26 '12 at 15:51

3 Answers3

3

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";
Borodin
  • 126,100
  • 9
  • 70
  • 144
  • nice ...my first lession is helping me to create curiousity for the language...I did not get results in last command - my $DNA3 = "$DNA1$$DNA2"; print "$DNA3\n\n"; there is an error " Can't use string ("TTTTGGGTTTGAAAT") as a SCALAR ref while "strict refs" in use at C:\myperllessions\dnacon1.plx line 11." – jon Feb 26 '12 at 16:29
  • That line should be updated, either with `my $DNA3 = "$DNA1\$$DNA2";` or with `my $DNA3 = "$DNA1$"."$DNA2"` (would prefer the first one). The reason why it gives an error is because parser tries to interpolate the longest string available - effectively ${$DNA2}, the symbolic reference, which is effectively disabled earlier (by use strict). – raina77ow Feb 26 '12 at 16:41
  • I suppose it was just a typo, though, as you'd probably intend to just concatenate both strings. Then, again, you may write as `my $DNA3 = "$DNA1$DNA2";` or, a bit more readable, `my $DNA3 = $DNA1 . $DNA2;` – raina77ow Feb 26 '12 at 16:46
  • And, by the way, you probably want to write #! instead of #i. The first is so-called hash-bang, used to indicate what program should be used to process the file; afaik, it's of little use at Win platform, though. – raina77ow Feb 26 '12 at 16:49
2

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

Unos
  • 1,293
  • 2
  • 14
  • 35
1

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.

darnir
  • 4,870
  • 4
  • 32
  • 47