How do I run a Perl program from a Windows platform?

AI Thread Summary
To run a Perl program on a Windows platform, the user must ensure that ActivePerl is correctly installed and that the PATH environment variable includes the directory where Perl is installed, typically C:\Perl\bin. To execute a Perl script, open a command prompt (cmd), navigate to the script's directory using the "cd" command, and run the script with "perl scriptname". If issues arise, checking the installation and PATH settings is crucial. In the discussion, users also shared experiences with handling large text files in Perl, noting that while Perl excels in string manipulation, it struggles with large datasets. Suggestions included optimizing the script for efficiency and exploring alternative programming languages like Python for better readability and performance. Users discussed specific coding challenges, such as capturing data from formatted text files and leveraging regular expressions for pattern matching. The conversation highlighted the importance of understanding basic command-line operations and the potential need for more comprehensive documentation from Perl resources.
Monique
Staff Emeritus
Science Advisor
Gold Member
Messages
4,211
Reaction score
68
How do I run a Perl program from a Windows platform? I installed Collie Perl Shell for the text editing, and I installed ActivePerl for Windows... but.. what part of ActivePerl should I use to give command lines to run a program? :rolleyes:

I've been going through the user guide, but it's not making me any wiser
 
Computer science news on Phys.org
Whatever directory Perl is installed into (I think C:\Perl is the default) should contain a bin directory with a perl.exe program inside. You use it to run perl scripts; just pass it the name of the script as a parameter on the command line.
 
ah thanks, but that still does not work for me.

This is what it says in the documentation:
In the /eg directory of your Perl install there is a sample script named example.pl To run it, launch a console window, make the /eg directory your current working directory and type:

perl example.pl
You should see:
"Hello from ActivePerl!"

If you do, you've successfully installed ActivePerl! If not, there's something wrong with your installation. Check to make sure that your PATH environment variable includes the directories to which you installed the Perl core binaries. (You can type set at the command prompt to see what's in your Path.) If you chose the defaults during the install, these should be set to the correct values for you when you start a new command prompt.

One last note: typing perl -h will display all of the available command line options available to you.

I launched the perl.exe and typed
perl -h
but nothing is happening :zzz:

I uninstalled and reinstalled the ActivePerl, but that didn't help anything. Suggestions?

Also:
1) what is a console window
2) how do I make /eg my working directory? using Unix commands like pwd and cd?
 
The console is just a command-line interface; basically, a DOS prompt. Yes, in order to change the current working directory you have to use the "cd" command.

To bring up a console, just go to Start > Run, type in "cmd" and hit OK. This should bring up a black window with a command line. Type in "cd C:\Perl\eg" and hit enter to go to the /eg directory, and then type in "perl example.pl" and hit enter to run the example script.

Other scripts can be run in a similar way. Just cd to the directory with the script and type "perl scriptname" to run the script.
 
:eek: ahhhhhhhh, great :biggrin:

why don't they say that in their documentation?
it's working now, thanks
 
lol.
its all understood monique...
those are the basic commands of DOS ...
 
they should have said to open dos promt :rolleyes: :shy:
 
:biggrin: :biggrin: Just wrote my own program and it's working on a small text file... but my text file is 35 million letters long and my computer can't handle it.. or I'd have to run it for half an hour or so :cry:

Code:
!C:\Perl\bin\perl -w
use strict;

open IN, "fuse.txt";
#open OUT, ">output.txt";

my $sequence="";
my @intron_array;
my $intron;
my $counter=0;

[b]This part is easy, I remove lines with ">" in the file and compile
the rest into a single long string so that I have one long text file.[/b]
while (<IN>){
    if ($_!~/>/){
        chomp;
        $sequence=$sequence.$_;
#        print OUT $sequence;
    }
}

[b]Here I do a pattern match, where I print the first pattern
found and want to know how many other patterns are found.[/b]
@intron_array= ($sequence=~m/(GTA[A|T]GT\w{25,35}[A|G]CTAA[C|T]\w{5,10}[C|T]AG)/g);

foreach $intron(@intron_array){
    #print $intron."\n";
    $counter++;
}
print "Eerste intron = ".$intron_array[0]."\nAantal introns= ".$counter;
Is there any way that I can make the script more efficient or do I just have to let my computer crunch the numbers? Thanks.
 
Ok, took 40 minutes to run it twice so :approve:
 
  • #10
I'm impress Monique. Before I know it you'll be a tech guru :approve:
 
Last edited:
  • #11
he he ...
not bad ...

thats the only prob with PERL...
very good for string handling, but very poor for handling bulk files ...
 
  • #12
Question:

I have the following file with hard returns
Code:
>organism 1.1 (build 1)
[b]TTATTAAAGTATGTTAGTGTAAGACGAGAGTTTTT
ATTAAAGTATGTTAGTGTAAGACGAGAGTTTTTGG[/b]
>organism 1.1 (build 2)
[b]CCTATTAGCAAAACTAAACCTGTTAGTTGTAGGGT
GCTTCCTATTAGCAAAACTAAACCTGTTAGTTGTA[/b]
How do I capture the data that is bolded, into 2 separate variables? I can't get it to work :cry: :cry:
 
  • #13
simple
just search for those strings and continue ...

may b u had the prob with those '\n' (new lines)...
is that so ?
 
  • #14
Yes, I tried the following regular expression that searches for this pattern

chomp;
@contig_array=($_=~/\)(.*)>/g);
print @contig_array;

but I don't get anything returned :(
 
  • #15
Is this what your looking for?

Code:
#!/usr/bin/python

list = []
str = ""

for line in open('infile'):
  if line[0] != '>':
    str += line.rstrip()
  elif str != "":
    list.append(str)
    str = ""
list.append(str)

print list

As you can probably tell the code above is in Python. I find Python much easier to read and program in than Perl.

The result is:

["TTATTAAAGTATGTTAGTGTAAGACGAGAGTTTTTATTAAAGTATGTTAGTGTAAGACGAGAGTTTTTGG", "CCTATTAGCAAAACTAAACCTGTTAGTTGTAGGGTGCTTCCTATTAGCAAAACTAAACCTGTTAGTTGTA"]

If you need to count how many instances a regex pattern appears Python has a function called findall() which will return a list of all the pattern instances. You can then use the len() function to find out how many instances where found.

[edit] Hmm, must be a bug with the forum. There shouldn't be a space inside the output string.
 
Last edited:
  • #16
karthik3k said:
simple
just search for those strings and continue ...

may b u had the prob with those '\n' (new lines)...
is that so ?
"just search for those strings anc continue"
:smile: you know how large my document is?

dduardo, I think I did something like that but I don't like the solution.. I think I can best solve it with an associative array that is defined like this %file=($header,$sequence) .. now I just need to think of a right way to code that..
 
  • #17
I still don't understand what your after.

You basically have a very large file with many lines of this:

Code:
>organism 1.1 (build 1)
TTATTAAAGTATGTTAGTGTAAGACGAGAGTTTTT
ATTAAAGTATGTTAGTGTAAGACGAGAGTTTTTGG
>organism 1.1 (build 2)
CCTATTAGCAAAACTAAACCTGTTAGTTGTAGGGT
GCTTCCTATTAGCAAAACTAAACCTGTTAGTTGTA

You want to ignore all the lines that begin with ">", but concatenate all the content within each build into separate variables.

Now how does the regex fit into this? Do you want to search a variable for a specific pattern and then look through all the other variables to see if it can find that same pattern?

With a dictionary (aka associative array) you need to know the key name to access the data. With a list you can just loop through it with a counter.

If for each build you want each line to be stored seperately you can do a list within a list. Something like this:

Code:
[["TTATTAAAGTATGTTAGTGTAAGACGAGAGTTTTT","ATTAAAGTATGTTAGTGTAAGACGAGAGTTTTTGG"],["CCTATTAGCAAAACTAAACCTGTTAGTTGTAGGGT","GCTTCCTATTAGCAAAACTAAACCTGTTAGTTGTA"]]
 
Back
Top