my $search =$ARGV[0]; summary_o(); #summary_no(); my @count; my @matches; my $ofound =""; #my $nfound; sub summary_o { open INPUT,"/home/perlcourse/derek/final/oncogenic_E1.txt" or die $!; my $count =-1; #I have added a last ">" symbol into my text file to make this code run. my $seq =(); my $hits; my $header; my $pos; my %o; my $contains =0; my $searchline; my @poz; while (my $line =) { if ($line =~m/^>/) { if ($seq) { $o{$header} = "$seq"; } $count++; print "\n\n"; print "$line"; $header = "$line"; $seq=(); } else { chomp $line; print $line; $seq .= "$line"; } #Q: How many times is the $search found inside all the hash values?? } while (my ($key,$value) = each(%o)) { $hits++ while $value =~ /$search/gi; } #Q: How many hash values contain at least one “$search” inside of them? #################### #FOREACH LOOP START# #################### foreach my $key (keys %o) { $searchline = $o{$key}; if ($searchline =~ /$search/gi) { $contains ++; } } ################### # FOREACH LOOP END# ################### print "\n\t\t*****Summary of input*****\n"; if ($hits) { print "\nThere are " . $hits. " matches of " .$search ." in " . $count ." sequences."; } else { print "\n\nThere are 0 matches in " . $count . " sequences."; } print "\n$contains" . " sequences out of ".$count." contain the query sequence at least once." if ($contains); print "\n\n"; if ($count) { my $ofound = ($hits)/($count); } elsif ($count ==0) { } close (INPUT); #print $ofound; print "\n"; return $ofound; }