in reply to Best Practice: How do I pass option parameters to functions?
The same logic went for a generic output module to handle variable and uncertain output environments (writing to console, writing to a web page as part of CGI response, writing to a printer, etc.). A special module handles all the configuration and execution details; no special parameters to invoke the work routines of my programs, but when I call the output function it translates, encapsulates, and otherwise transmogrifies the data and puts it out the correct doorway.
As noted by others, it's still a global-thinking approach, but it doesn't pollute main::namespace, and the modification of its attributes requires a bit more intentional effort than accidentally setting the wrong variable. These are the evils of global variables, and they are avoided by shoving the global function off into its own module.
|
|---|