CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Need a Custom or Prewritten Perl Program?: I need a program that...:
complex Perl program


New User

Feb 28, 2011, 12:48 AM

Post #1 of 7 (6496 views)
complex Perl program Can't Post

This is regarding a small project, where i will have store 20 alpahbets in pairs(characters in the form of array in pasirs, like AA AB wise), and compare the input sequence like ABCDG.... with the pairs.

To explain in detail:if the ssequence is ABCDG, then first two characters will be compared with the existing pairs( 20 characters in the form of array in pairs, like AA AB wise) if avaiable notify with count,
i.e AB compare with all pairs like AA ,AB .. then BC compare with AA, AB .....and so on..

To put it more simple..i need to hard cord 20 alphabets(A,B,C,D, combinations like AA,AB, it comes around 300+ combinations) , then compare the input sequence ABCDA...with these hard cored pairs..but the inpout sequence will be compared like 1-2, 2-3, 3-4(AB,BC,CD)....

Please help me, thanks in Advance.



Feb 28, 2011, 4:08 PM

Post #2 of 7 (6480 views)
Re: [selvankj] complex Perl program [In reply to] Can't Post

This seems to be about what you want. Please comment.

use strict; 
use warnings;
my $sequence = <DATA>;
my %pair_counts;
for my $i (0..length($sequence)-2) {
my $pair = substr $sequence, $i, 2;
next if ($pair =~ /[^ABCDEFGHIJKLMNOPQRST]/);

foreach my $pair (sort keys %pair_counts) {
printf "%s %2.0f\n", $pair, $pair_counts{$pair};

Good Luck,

New User

Feb 28, 2011, 9:30 PM

Post #3 of 7 (6474 views)
Re: [BillKSmith] complex Perl program [In reply to] Can't Post

First of i thank you very much for talking time and replying..

Am not able to understand the below code properly...sorry am just a beginer(am actually new to programming)...i trying to analyse your code and work it out..meanwhile if i have confused you with equirement here in more detail.

point 1:my requirement is.. i have few combinations AA AB AC BA BB BC CC CA CB wise 300+ combinations..

point2 :now my input sequence is ABCDE

wht it should do is... AB of input sequence will be checked in all the 300+ then BC then CD then DE like wise

i.e if input is ABCDE ..and we number it as 12345 then 1,2(AB) compare with 300 combinations then 2,3(BC) with 300 combinations then 4,5(CD) and so on..

while comparing if the pair is found in the 300+ combinations then it should diplay the count.


Exmaple input: ABCDEAB compare against(300 combinations like AA AB AC and so on..)

OUTPUT: AB-2 BC-1 CD-1 DE-1 EA-1



Mar 1, 2011, 6:10 AM

Post #4 of 7 (6465 views)
Re: [selvankj] complex Perl program [In reply to] Can't Post

My script counts all 400 possible pairs of the 20 letters A through T. It examines every pair in the sequence. If it contains a character not in the set, it goes to the next pair. Otherwise, it uses the pair as a key into the counts hash and increments the value. When it is finished counting, it prints the contents of the hash. The strange line at the end is a test sequence which I made by random banging on the keyboard.

Run the script as is. Check the results by hand.

You can try it with a real sequence by changing the regular expression to contain the correct 20 characters and by replacing my sequence with a real one. If that much meets your requirements, we can discuss user interface requirements and the elimination of unwanted pairs.

It seems you do not want most but not all of the 400 pairs. It probably is easier to count all the pairs and ignore the few you do not need than it would be to count only the required ones.
Good Luck,

New User

Mar 1, 2011, 9:45 AM

Post #5 of 7 (6456 views)
Re: [BillKSmith] complex Perl program [In reply to] Can't Post

Thanks Bill. The script worked perfectly. Is it possible to run the script for the input data which is quite large (approx. 1500 characters), also for about quite a large number of entries and then save the output corresponding to each entry in a file?

Awaiting your reponse.



Mar 1, 2011, 11:23 AM

Post #6 of 7 (6450 views)
Re: [selvankj] complex Perl program [In reply to] Can't Post

Your 1500 character file is not really very large, it should not be a problem. The attached script is the same as the previous except that it reads from a file and writes to a file (both specified on the command line).

perl mysequence.dat mypaircount.dat

I changed the output format slightly. It is not necessary or even desirable to line up the columns in a file. The script reports, on the screen, the total number of pairs counted. This is to assure you that the script did complete without errors.
Good Luck,
Attachments: (0.72 KB)

New User

Mar 1, 2011, 11:54 PM

Post #7 of 7 (6432 views)
Re: [BillKSmith] complex Perl program [In reply to] Can't Post

Thanks a lot Bill. I will try the code you have attached.

- Thiru


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives