Lost Password?

Go Back   CodeCall Programming Forum > Web Development Forum > Perl

Perl Discussion for the PERL language - Practical Extraction and Reporting Language, is a programming language often used for creating CGI programs.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-03-2007, 10:52 PM
lichy lichy is offline
Newbie
 
Join Date: Jun 2007
Posts: 17
Rep Power: 5
lichy is on a distinguished road
Default help

i need help.

for example, my input is AAXXXAAXXXAAXX

so i want to count the number of times the AA actually appear in total. that will be 3 times. how to write a program like this?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 09-04-2007, 12:47 AM
KevinADC KevinADC is offline
Learning Programmer
 
Join Date: Jan 2007
Posts: 89
Rep Power: 6
KevinADC is on a distinguished road
Default

double-post, see below.........

Last edited by KevinADC; 09-04-2007 at 12:51 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-04-2007, 12:48 AM
KevinADC KevinADC is offline
Learning Programmer
 
Join Date: Jan 2007
Posts: 89
Rep Power: 6
KevinADC is on a distinguished road
Default

Really mate, this is too simple, next time post some code you have tried.

two ways:

Code:
$input = 'AAXXXAAXXXAAXXAXA';
$count = $input =~ s/(AA)/$1/g;
print $count;

$input = 'AAXXXAAXXXAAXXAXXA';
$count = () = $input =~ /AA/g;
print $count;
but what is if the input has three or more 'A's in a row? For example:

AAXXXAAXXXAAXXAXAAAXXAAAAAXXAA
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-06-2007, 12:37 AM
lichy lichy is offline
Newbie
 
Join Date: Jun 2007
Posts: 17
Rep Power: 5
lichy is on a distinguished road
Default

as for that, i still have to verify with my teacher in school. to see what he gonna say about that.

btw thanks for helping.

input : AAXXXXAAXXXACXXXACXXX

i would like to count the times AA and AC occurred separately.

i try using your method. but the output is not what i want.
and i try using "if" statement. it's still the same output which is not what i expected.

this is the code for "if" statement.

if($seq =~ AA)
{
$countAA = $seq =~ s/(AA)/$1/g;

print "\nNumbers of AA pairs occurred: $countAA";
}

if($seq =~ AC)
{
$countAC = $seq =~ s/(AC)/$1/g;

print "\nNumbers of AC pairs occurred: $countAC";
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 09-06-2007, 03:14 AM
KevinADC KevinADC is offline
Learning Programmer
 
Join Date: Jan 2007
Posts: 89
Rep Power: 6
KevinADC is on a distinguished road
Default

the "if" conditions are not necessary:

Code:
$seq = 'AAXXXXAAXXXACXXXACXXX';
$countAA = $seq =~ s/(AA)/$1/g;
print "\nNumbers of AA pairs occurred: $countAA";
$countAC = $seq =~ s/(AC)/$1/g;
print "\nNumbers of AC pairs occurred: $countAC";

both substrings (AA and AC) are counted twice, so the code works as expected.

From now on if you post questions I will not reply unless i see the code you have been writing and trying. That is my personal policy for helping students.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 09-11-2007, 11:49 PM
lichy lichy is offline
Newbie
 
Join Date: Jun 2007
Posts: 17
Rep Power: 5
lichy is on a distinguished road
Default

ok noted.

btw instead of putting

$count = $seq =~ s/(AA)/$1/g;
print $count;

can i put

$count = $seq =~ s/($codon)/$1/g;
print $count;

as for the $codon, it's a input for the user to type in.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 09-12-2007, 08:47 PM
KevinADC KevinADC is offline
Learning Programmer
 
Join Date: Jan 2007
Posts: 89
Rep Power: 6
KevinADC is on a distinguished road
Default

try it and see what happens. This is the kind of thing that is easy to run a test on and see what the results are.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT -5. The time now is 08:36 AM.

Contest Stats

John ........ 223.00000
dargueta ........ 168.00000
Xav ........ 164.00000
gaylo565 ........ 18.00000
WingedPanther ........ 15.00000
|pH| ........ 15.00000
Johnnyboy ........ 3.00000
navghost ........ 1.00000

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 66%

Ads