# File: count2.pl # Title: Asks for a string (DNA string). Alphabet is acgt # Count the occurrences of all letters in the give alphabet in the string # Author: Mihaela Malita # What string? acgtacgataga # Occurences of a = 5 # Occurences of c = 2 # Occurences of g = 3 # Occurences of t = 2 print "What string? "; $S = ; chop($S); $count_a = 0; # initialize counter $count_c = 0; # initialize counter $count_g = 0; # initialize counter $count_t = 0; # initialize counter @S = split('', $S); # transforms string in array foreach $i ( @S ) { # for every element in array if ($i eq 'a'){ ++$count_a }; # increments counter $count_a if ($i eq 'g'){ ++$count_g }; # increments counter $count_g if ($i eq 'c'){ ++$count_c }; # increments counter $count_c if ($i eq 't'){ ++$count_t }; # increments counter $count_t } print "\nOccurences of a = $count_a"; print "\nOccurences of c = $count_c"; print "\nOccurences of g = $count_g"; print "\nOccurences of t = $count_t"; exit;