Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi -- I'm working on writing code to check each string within an array. This is directed at checking that a DNA input contains only A, T, C, and G. I have written it such that you can input your DNA sequence on the command line. When I run this with an input such as "ATGTCAHCGT," I get nothing back where I should get a print statement of "Non-nucleotide at 6 position." What I am missing/ where am I going wrong? Any help much appreciated. Cheers, A
my $dna_input = $ARGV[0]; # turn command line input into a variable my @dna = split("", $dna_input); #split the variable into an array so +as to check each nucleotide my $count = 0; # keep track of position so as to report where there is + a non-nuceloetide character my $base; foreach $base (@dna) { if($base eq 'A' || 'T' || 'C' || 'G') { $count += 1; } else { print "Non-nucleotide at $count position\n"; } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: If/else within a foreach loop to check strings within an array
by choroba (Cardinal) on Oct 19, 2013 at 22:01 UTC | |
by Anonymous Monk on Oct 19, 2013 at 22:05 UTC | |
Re: If/else within a foreach loop to check strings within an array
by LanX (Saint) on Oct 19, 2013 at 22:03 UTC | |
Re: If/else within a foreach loop to check strings within an array
by BrowserUk (Patriarch) on Oct 19, 2013 at 22:39 UTC | |
by LanX (Saint) on Oct 19, 2013 at 22:47 UTC | |
by BrowserUk (Patriarch) on Oct 19, 2013 at 23:01 UTC | |
Re: If/else within a foreach loop to check strings within an array
by drmrgd (Beadle) on Oct 20, 2013 at 11:46 UTC | |
Re: If/else within a foreach loop to check strings within an array
by boftx (Deacon) on Oct 20, 2013 at 19:53 UTC |
Back to
Seekers of Perl Wisdom