exercism-perl5

Repository for my Perl 5 Exercism exercises
git clone git://git.samirparikh.com/exercism-perl5
Log | Files | Refs

commit e61652e4b8820e795df8d92ccf24baecd5b37e66
parent 6f05e2607b226a9cdae9ee76e2f4a5fa8c38c40d
Author: Samir Parikh <noreply@samirparikh.com>
Date:   Sat, 27 Nov 2021 16:38:56 +0000

update NucleotideCount.pm

Diffstat:
Mnucleotide-count/NucleotideCount.pm | 16+++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/nucleotide-count/NucleotideCount.pm b/nucleotide-count/NucleotideCount.pm @@ -6,7 +6,21 @@ our @EXPORT_OK = qw<count_nucleotides>; sub count_nucleotides { my ($strand) = @_; - return undef; + my %count = ( + 'A' => 0, + 'C' => 0, + 'G' => 0, + 'T' => 0 + ); + #print "\$strand is $strand\n"; + if ($strand =~ /[^ACGT]/) { + return "Invalid nucleotide in strand"; + } else { + foreach (split //, $strand) { + $count{$_}++; + } + } + return \%count; } 1;