#!/lusr/bin/perl -w use strict; my $total_length = 0; my %charCount = (); #open_file(); #process_file(); #compute_value(); #print_total(); sub open_file { print "Enter filename: "; my $filename = ; open (SEQUENCE, $filename) or die "Can't open the DNA sequence file: $filename\n"; } sub process_file { while (){ chomp($_); my $length = length($_); for (my $i = 0; $i < $length; $i++){ my $char = substr($_, $i, 1); $charCount{$char}++; } $total_length += $length; } close(SEQUENCE); } sub compute_value { foreach my $char (keys %charCount){ my $fraction = 100 * $charCount{$char} / $total_length; print "The character $char occurs $charCount{$char} times, or $fraction %\n"; } } sub print_total { print "Total length is $total_length.\n"; } open_file(); process_file(); compute_value(); print_total();