# File: tr2.pl # Author: Jason L. Bryant # Title: Makes a string of characters from an alphabet, and counts # the occurences of each letter (counting with tr). To Improve! # Alphabet = a c g t # Length of string? 5 # Generated String is acgaat # Occurrences of A= 3 # Occurrences of C= 1 # Occurrences of G= 1 # Occurrences of T= 1 @Alpha = ('a','c','g','t'); print "Alphabet is @Alphabet"; print "Length of string)? "; $n = ; chop($n); $s = ''; # initialize final string s with empty '' for ( 1..$n ) { $pos = int rand(4); # generates random integer < 4 $s = $s . $Alpha[$pos]; # concatenation with . } print "Generated string is $S\n"; $_ = $s; $Ka = tr/a/a/; #counts how many a's $Kc = tr/c/c/; #counts how many c's $Kg = tr/g/g/; #counts how many g's $Kt = tr/t/t/; #counts t print "Occurrences of A= $Ka\nOccurrences of C= $Kc\n"; print "Occurrences of G= $Kg\nOccurrences of T= $Kt\n"; exit;