Hallo everyone
im starting to learn perl and i have a problem , i have an exercise asking me to count all the letters each apart in a DNA string , for example
my @DNA =( ctagctagcatgacgatacatgacagataggatacagatagacagatacagatacagatacagatagacccatgacagatac)
so i have to make a perl script showing the user how many t's , a's , c's and g's he typed , what a mean , if the user of the perl script type CTGACTGACGTACGTACGTA , the perl script have to show him how many a's t's c's and g's he typed ....
hoping for help ,,, thanks a lot
wannagethelp
0
Newbie Poster
Recommended Answers
Jump to Posttry something like:
$tcount; $acount; $gcount; $ccount; foreach $letter (@DNA) { if (($letter eq "t" ) || ($letter eq "T")) { $tcount++: } and so on
Jump to PostUnless you have to use an array you could also do the following.
#!/usr/bin/perl -w #CountLetters.pl use strict; print "Enter string of letters: "; chomp (my $input = <STDIN>); my ($char, $count, $verb, $s); print "\n"; while ($input =~ m/(.)/g) { $char = $1; #Count and remove …
All 8 Replies
eggmatters
21
Junior Poster in Training
d5e5
109
Master Poster
ithelp
757
Posting Virtuoso
Banned
wannagethelp
0
Newbie Poster
d5e5
109
Master Poster
vbharathi
3
Newbie Poster
eggmatters
21
Junior Poster in Training
wich
-2
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.