in reply to I'm trying to consolidate my functions into subroutines
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}) ... } ... }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: I'm trying to consolidate my functions into subroutines
by haukex (Archbishop) on May 13, 2017 at 17:38 UTC | |
by Anonymous Monk on May 13, 2017 at 17:44 UTC | |
by AnomalousMonk (Archbishop) on May 13, 2017 at 17:48 UTC | |
by LanX (Saint) on May 13, 2017 at 17:48 UTC | |
|
Re^2: I'm trying to consolidate my functions into subroutines
by AnomalousMonk (Archbishop) on May 13, 2017 at 17:44 UTC |