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

Click For Summary

Discussion Overview

The discussion revolves around running Perl programs on a Windows platform, specifically addressing installation issues, command line usage, and script efficiency. Participants share their experiences and seek solutions to problems encountered while executing Perl scripts and handling large text files.

Discussion Character

  • Technical explanation
  • Conceptual clarification
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant inquires about running a Perl program using ActivePerl and seeks guidance on command line usage.
  • Another participant suggests that the Perl executable can be found in the bin directory of the installation and provides instructions on how to run a script from the command line.
  • A participant expresses frustration with the documentation and reports issues with running the example script, prompting further troubleshooting suggestions regarding the PATH environment variable.
  • Participants clarify the concept of a console window and provide instructions on how to navigate directories using command line commands.
  • One participant successfully runs their own Perl program but encounters performance issues with processing a large text file, questioning if there are ways to improve efficiency.
  • Another participant shares a Python solution for processing similar data, expressing a preference for Python over Perl for readability and ease of use.
  • Several participants discuss strategies for capturing specific data patterns from a large file, with varying suggestions on using regular expressions and data structures.

Areas of Agreement / Disagreement

Participants generally agree on the basic commands needed to run Perl scripts from the command line, but there are differing opinions on the efficiency of Perl for handling large files compared to other programming languages like Python. The discussion on how to capture specific data patterns remains unresolved, with multiple approaches suggested but no consensus reached.

Contextual Notes

Some participants express uncertainty about the effectiveness of their regular expressions and the handling of newline characters in their data. There are also mentions of potential bugs in the forum affecting code output.

Who May Find This Useful

This discussion may be useful for individuals learning to run Perl on Windows, those facing challenges with script performance, and programmers interested in comparing Perl and Python for data processing tasks.

Monique
Staff Emeritus
Science Advisor
Gold Member
Messages
4,229
Reaction score
61
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 separately you can do a list within a list. Something like this:

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

Similar threads

Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
6K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 18 ·
Replies
18
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 18 ·
Replies
18
Views
3K
  • · Replies 37 ·
2
Replies
37
Views
7K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K