I used this little piece of code grabbed in my bigger script as a subroutine.

sub revcompl { my (@dna) = @_; foreach my $segment (@dna) { my $revcomp = reverse($segment); $revcomp =~ tr/ACGTacgtMKRYBDmkrybdhv/TGCAtgcaKMYRVHDBkmyrvhdb/; push @dr, $revcomp;} $done = join('',@dr); return $done; }

I had a has in my script connecting bunch of identification numbers with sequences. When I wanted to grab a sequence by a ID and run it through the sub.Lets say ..

$stringforsequence=$hashofseqs{someIDnr}; $reversedsequence=revcompl($stringforsequence); print "$reversedsequence";

Then what I got was a printout of reverse complements for EVERY single sequence in %hashofseqs. (Printout that shows that subroutine is ran on all "value" strings contained in hash) For print command or other such manipulations $stringforsequence is exactly what I would expect from it, a single sequence that corresponds to a certain someIDnr key.

How come that this string somehow passes the whole of the hash into the subroutine? How could this be avoided? It is my first script actually containing some hashes. I try to learn a bit about them as they seem to be rahter useful elements for many a data manipulation. But as for now I'm rather dumbfounded.


In reply to Why does this sub grab the whole hash by naturalsciences

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.