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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |