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

1. Jan 27, 2005

### Monique

Staff Emeritus
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? :uhh:

I've been going through the user guide, but it's not making me any wiser :grumpy:

2. Jan 27, 2005

### master_coda

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.

3. Jan 27, 2005

### Monique

Staff Emeritus
ah thanks, but that still does not work for me.

This is what it says in the documentation:
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?

4. Jan 27, 2005

### master_coda

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.

5. Jan 27, 2005

### Monique

Staff Emeritus
ahhhhhhhh, great

why don't they say that in their documentation? :grumpy:
it's working now, thanks

6. Jan 27, 2005

### karthik3k

lol.
its all understood monique...
those are the basic commands of DOS ...

7. Jan 27, 2005

### Monique

Staff Emeritus
they should have said to open dos promt :shy:

8. Jan 27, 2005

### Monique

Staff Emeritus
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

Code (Text):
!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.

9. Jan 27, 2005

### Monique

Staff Emeritus
Ok, took 40 minutes to run it twice so

10. Jan 27, 2005

### The_Professional

I'm impress Monique. Before I know it you'll be a tech guru

Last edited: Jan 27, 2005
11. Jan 28, 2005

### karthik3k

he he ...

thats the only prob with PERL...
very good for string handling, but very poor for handling bulk files ...

12. Jan 28, 2005

### Monique

Staff Emeritus
Question:

I have the following file with hard returns
Code (Text):
>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 seperate variables? I can't get it to work

13. Jan 28, 2005

### karthik3k

simple
just search for those strings and continue ....

may b u had the prob with those '\n' (new lines)...
is that so ???

14. Jan 28, 2005

### Monique

Staff Emeritus
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. Jan 28, 2005 ### dduardo Staff Emeritus Is this what your looking for? Code (Text): #!/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.  Hmm, must be a bug with the forum. There shouldn't be a space inside the output string. Last edited: Jan 28, 2005 16. Jan 30, 2005 ### Monique Staff Emeritus "just search for those strings anc continue" :rofl: 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. Jan 30, 2005

### dduardo

Staff Emeritus
I still don't understand what your after.

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

Code (Text):

>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 seperate 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 (Text):

[["TTATTAAAGTATGTTAGTGTAAGACGAGAGTTTTT","ATTAAAGTATGTTAGTGTAAGACGAGAGTTTTTGG"],["CCTATTAGCAAAACTAAACCTGTTAGTTGTAGGGT","GCTTCCTATTAGCAAAACTAAACCTGTTAGTTGTA"]]