Is this done?
Instead of calling a sub with a defined set of parameters, call it
instead with a single string. This string is tokenized and then
GetOpt called to sort out the mess.
Getopt usually works on a list of strings.
As some of my sub get "optiony" I see a use for this construct. While
I should probably create new subs for some of the option
configurations, I was curious about this use of Getopt.
[...]
Always curious about the way the pros do it.
This depends somewhat on how subroutines are being used. There are
basically two competing approaches here:
1. "I have to dig a tunnel below Mordor with a teaspoon until tomorrow
so I'd better start shoveling!" aka 'subroutines are not being used'
(except insofar they can be downloaded from the internet free of
charge). That's the traditional way to avoid structuring a program and
much beloved by people with an excellent short-term memory who prefer
to 'keep on shoveling' until the problems runs out instead of designing
a machine which solves the problem. In this case, how subroutine
arguments are dealt with pretty much doesn't matter: There's exactly one
'subroutine' and maybe it had some arguments 6,500 lines in the past but
nobody can remember if it did and in any case we gotta keep on shoveling
instead of being distracted with silly questions like that.
2. Subroutines are being in a way known as 'functional decomposition',
that is, each subroutine corresponds with an 'abstraction layer' and it
is invoked by more abstract subroutines and invokes less abstract
ones. In this case, there'll be many subroutines and they're typically
short (30 lines of code or less). Likewise, parameter list are going be
short (1 - 4 parameters) and arguments will usually be accessed by
position because that's faster and more elaborate schemes aren't
needed. Should an elaborate scheme for dealing with subroutine arguments
be needed, this would indicate that the subroutine in question does too
many different things and should be further decomposed.
I usually prefer 2) becauses this provides a reasonably simple way to
solve complicated problems, however, creating seriously complicated
solutions to simple problems is also very popular ...