Hi, I realize this may a bit of code...I am including a large portion because I am having trouble returning the variable $ofound so that I may print it (and use it for more calculation...) outside of the subroutine.

Any thoughts?

THANKS!

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 =<INPUT>) { 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 qu +ery 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; }

In reply to Returning from a subroutine. by MaroonBalloon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.