|Keep It Simple, Stupid|
Refactoring: sub within a subby temporal (Pilgrim)
|on Jul 25, 2012 at 19:29 UTC||Need Help??|
temporal has asked for the
wisdom of the Perl Monks concerning the following question:
I am cleaning up some scripts and ended up pulling an entire script with its subroutines into another script - as a subroutine. Something like:
Like in the example, I have to keep these subroutines in scope so that some variables that are defined in the outer subroutine are available.
I don't want to make these variables global. I have a lot going into this script and I'm trying to keep things organized. I want all of my globals to be things that are used by more than one subroutine.
Some more background:
Essentially, I am writing a module that contains a collection of 'tasks'. A superscript to this one will be importing and calling these tasks individually and for different times, triggers, etc. This is one module of many. Each module will contain the same 'tasks' (same named subroutines) such that my superscript can iterate through them all easily.
Anyway, I checked out Defining a sub within a sub: OK?, but I'm not sure if it exactly answers my question. Why are anonymous subs more acceptable? I just want to get some feedback/suggestions since this seems like something that might be considered... poor Perl form.