TL;DR - see Coping with Scoping


In your code you have called the first subroutine like this:

HashSequences();

But that subroutine returns values like this:

return (%seq, $id);

Since you call the subroutine in a void context those values are lost and the net result of this particular call to the subroutine is zero (bar a waste of time). If you want to return values from a subroutine and use them in the calling routine you must assign them in the calling routine. eg:

$bestday = max($mon,$tue,$wed,$thu,$fri);

That code is taken from the very first example in perlsub which I hope you have read. See how the result on the right is assigned to a variable on the left? That's what you need to do. If returning multiple items then the thing on the left should be a list or an array (forcing list context - you will need to start thinking about context a lot more).

The next problem with your return statement is that you are returning a hash and a scalar. But the return flattens all lists (including hashes) so this is not the correct way to proceed. You could use a reference but that's probably a few chapters down the line. For now, respect the basic approach which is to return all the scalars first so the calling routine knows where the list starts. eg. Change the return line to:

return ($id, %seq);

and call it like

my ($thisid, %thatseq) = HashSequences();

See the Writing Subroutines section of perlintro for more about the basics.


In reply to Re: I'm trying to consolidate my functions into subroutines by hippo
in thread I'm trying to consolidate my functions into subroutines by Peter Keystrokes

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.