in reply to Re^6: Aren't there code refs as well as function refs? (Update: refactoring very large sub with many variables)
in thread Aren't there code refs as well as function refs?
You don't need the brackets to share variables. But they are limiting the scope the same way like your giant function did before. I tried to guaranty a pain free refactoring.
FWIW you can also nest multiple layers of brackets. See Coping with Scoping for more.
The other approach is using OOP.
kcott also mentioned passing a hash around, that's actually one criteria for needing OOP, because (most) objects are just blessed hashes which are passed inside $self.°
so this could do too:
$obj->some_method { my ($self,@args) = @_; print $self-{many}, $self->{variables}; }
Cheers Rolf
(addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
Wikisyntax for the Monastery
°) one criteria of many, it depends on the concrete use case
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: Aren't there code refs as well as function refs? (Update: refactoring many variables into hash or object)
by cavac (Prior) on Mar 06, 2023 at 13:52 UTC | |
by LanX (Saint) on Mar 06, 2023 at 14:04 UTC | |
by cavac (Prior) on Mar 06, 2023 at 14:56 UTC | |
by LanX (Saint) on Mar 06, 2023 at 15:08 UTC |