it's actually creating global variables $id and %seq. But your subs don't use those global variables, they create their own variables by saying "my". Those "my" variables have the same name, but they are actually completely separate, so they don't actually share data with each other. Putting your data in global variables is arguably a bad habit, as it tends to inhibit code reuse. The "best practice" is to write something like this:SpecifySeqLengths(my $id, my %seq);
{ my $seq = HashSequences(); SpecifySeqLengths($seq); } sub HashSequences { my $seq = {}; ... $seq->{$id} .= $1; ... return $seq; } sub SpecifySeqLengths { my ($seq) = @_; ... for my $id (keys %$seq) { ... length($seq->{$id}) ... } ... }
In reply to Re: I'm trying to consolidate my functions into subroutines
by Anonymous Monk
in thread I'm trying to consolidate my functions into subroutines
by Peter Keystrokes
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |