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

In summary, the code is trying to count how many times the string "TTATTAAAGTATGTTAGTGTAAGACGAGAGTTTTT" appears in the file "infile". However, it doesn't seem to be working.
  • #1
Monique
Staff Emeritus
Science Advisor
Gold Member
4,219
67
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:
 
Computer science news on Phys.org
  • #2
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
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?
 
  • #4
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
:eek: ahhhhhhhh, great :biggrin:

why don't they say that in their documentation? :grumpy:
it's working now, thanks
 
  • #6
lol.
its all understood monique...
those are the basic commands of DOS ...
 
  • #7
they should have said to open dos promt :rolleyes: :shy:
 
  • #8
: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.
 
  • #9
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"
: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
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"]]
 

1. How do I install Perl on a Windows platform?

To install Perl on a Windows platform, you can go to the official Perl website and download the latest version for Windows. Once downloaded, simply run the installation file and follow the prompts to complete the installation.

2. Can I use Perl to create GUI applications on a Windows platform?

Yes, you can use Perl to create GUI applications on a Windows platform. There are several Perl libraries, such as Tk and Wx, that allow you to create graphical user interfaces for your programs.

3. How do I run a Perl program from the command line on Windows?

To run a Perl program from the command line on Windows, you first need to make sure that Perl is added to your system's PATH variable. Then, open the command prompt and navigate to the directory where your Perl program is located. Finally, type "perl .pl" and press enter to run the program.

4. Can I use Perl to interact with Windows system functions?

Yes, Perl has built-in support for interacting with Windows system functions. You can use modules such as Win32::API to access system functions and perform tasks like creating files and folders, manipulating the registry, and more.

5. Is it possible to compile Perl programs on a Windows platform?

Yes, it is possible to compile Perl programs on a Windows platform using a compiler such as ActivePerl or Strawberry Perl. This allows you to create standalone executable files that can be run on Windows computers without the need for Perl to be installed.

Similar threads

  • Programming and Computer Science
Replies
1
Views
323
  • Computing and Technology
Replies
6
Views
1K
  • Computing and Technology
Replies
18
Views
2K
  • Computing and Technology
Replies
18
Views
1K
  • Computing and Technology
2
Replies
37
Views
5K
  • Computing and Technology
Replies
12
Views
2K
  • Computing and Technology
Replies
12
Views
3K
  • Computing and Technology
Replies
5
Views
2K
  • Programming and Computer Science
Replies
15
Views
4K
  • Computing and Technology
Replies
17
Views
3K
Back
Top